相关疑难解决方法(0)

Android - 动态地将视图添加到视图中

我有一个视图布局 -

<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>
Run Code Online (Sandbox Code Playgroud)

我想要做的是,在我的主要活动中使用这样的布局

<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>
Run Code Online (Sandbox Code Playgroud)

我想循环遍历我的数据模型,并将包含第一个布局的多个视图注入主布局.我知道我可以通过在代码中完全构建控件来实现这一点,但我想知道是否有一种方法可以动态构建视图,以便我可以继续使用布局而不是将所有内容都放在代码中.

android view dynamic android-layout

141
推荐指数
5
解决办法
25万
查看次数

标签 统计

android ×1

android-layout ×1

dynamic ×1

view ×1