0
所以我很新的Android開發,我有以下情況:安卓:模板與XML
<LinearLayout
android:id="@id/child_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="">
<Button
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="">
</LinearLayout>
的問題是,我不得不重複這個水平的LinearLayout次未知量,爲每個新實例動態添加TextView和Button的文本字段。在水平的LinearLayout的每個新實例必須被添加到現有的垂直的LinearLayout。
因此,最初的垂直的LinearLayout:
<LinearLayout
android:id="@id/parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>
然後根據動態實現:
<LinearLayout
android:id="@id/parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@id/child_1">
</LinearLayout>
<LinearLayout
android:id="@id/child_2">
</LinearLayout>
</LinearLayout>
是沒有什麼辦法,跟我描述可以做到這一點?我在示例中使用的XML元素是基本情況。我實際上使用的是與它們相關的樣式屬性,所以我只想在XML中創建第一個LinearLayout,然後以編程方式訪問它,添加必需的字段,然後將其設置爲垂直的的垂直 LinearLayout 。
使用[列表視圖](http://developer.android.com/guide/topics/ui/layout/listview .html)。您可以根據需要自定義每行的外觀。 – Hemanth