【发布时间】:2011-09-07 04:13:18
【问题描述】:
我有一个视图的布局 -
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="0px"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/items_header"
style="@style/Home.ListHeader" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/items_none"
android:visibility="gone"
style="@style/TextBlock"
android:paddingLeft="6px" />
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/items_list" />
</LinearLayout>
我想做的是在我的主要活动中使用这样的布局
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="0px"
android:id="@+id/item_wrapper">
</LinearLayout>
我想循环遍历我的数据模型并将包含第一个布局的多个视图注入到主布局中。我知道我可以通过完全在代码中构建控件来做到这一点,但我想知道是否有一种方法可以动态构建视图,以便我可以继续使用布局而不是将所有内容都放入代码中。
【问题讨论】:
-
你可以查看这个stackoverflow.com/questions/3995215/…的答案
标签: android dynamic view android-layout