0

我想为 android 平台创建一个灵活的用户界面。

基本上我的布局将包括一个图像按钮,开头带有“加号”符号。当用户点击它时。调用另一个布局,提示用户命名假设创建的图像按钮。当用户单击确认时,他将返回第一个布局,新添加的图像按钮将替换“加号”符号图像按钮和加号图像按钮将向右移动。

我最初知道如何创建布局,但我不知道如何对其进行编程以按照我上面描述的方式运行。

好的,现在我的主布局文件是这样设置的:

<?xml version="1.0" encoding="utf-8"?>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true" >

<RelativeLayout 

    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#000000"  >
    <ImageButton
        android:id="@+id/addRoom"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="25dp"
        android:layout_marginTop="38dp"
        android:background="#80000000"
        android:src="@drawable/plus" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="@+id/addRoom"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/addRoom"
        android:layout_alignRight="@+id/addRoom"
        android:layout_below="@+id/addRoom"
        android:text="@string/add_room"
        android:gravity="center"
        android:textColor="#FFFFFF" />

    </RelativeLayout>
</ScrollView>

当我包含片段以移动图像按钮和文本视图时,我会遇到任何问题吗?

4

1 回答 1

2

当您想由用户实时操作活动的 UI 时,建议使用 Fragments 和 Fragment Manager 来更改活动视图的不同部分。

您可以在文档中找到重要信息:

http://developer.android.com/guide/components/fragments.html

或者

http://marakana.com/s/post/1250/android_fragments_tutorial

在你的情况下,你会做这样的事情:

fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.remove(plusButtonFragment)
.add(R.id.containerForFragments,userNewFragment)
.add(R.id.containerForFragments, plusButtonFragment)).commit();

在创建plusButtonFragmentuserNewFragment 之后

更新:

要在相对布局中管理片段位置,请查看下一篇文章:

如何在相对布局中以编程方式添加片段

于 2013-03-01T19:43:09.763 回答