我想爲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>
將我有任何問題,當我包括片段轉移圖像按鈕和TextView的當對準指示,兩者的它。
我理解你上面的示例代碼調用和替換圖像按鈕,但有沒有辦法設置擺放呢?我打算讓它每行2個圖像按鈕。我的xml佈局是相對佈局。 – user2124761 2013-03-02 09:12:07
查看更新的答案。 – 2013-03-02 13:38:42
我附上了我的佈局文件代碼 – user2124761 2013-03-02 15:18:40