【发布时间】:2013-10-07 15:04:19
【问题描述】:
我有这个父布局
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center|top"
android:text="Title"
android:textSize="20sp" />
<ListView
android:id="@+id/parent_listview"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
而parent_listview的列表项有这个布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" android:background="@color/mediumBlue" >
<TextView
android:id="@+id/sub_title"
android:layout_width="wrap_content"
android:layout_alignParentTop="true"
android:layout_height="wrap_content" />
<ListView
android:id="@+id/child_listview"
android:layout_width="wrap_content"
android:layout_height="250dp"
android:layout_below="@id/sub_title" >
</ListView>
</RelativeLayout>
child_listview 的项目有这个布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:background="@color/green" >
<TextView
android:id="@+id/childName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp" />
<TextView
android:id="@+id/childDesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp" >
</TextView>
</RelativeLayout>
我希望看到
Parent Layout
- Parent ListView
- Parent Item 1
-Child item 1
-Child item 2
-Child item 3
- Parent Item 2
-Child item 1
-Child item 2
- Parent Item 3
-Child item 1
- Parent Item 4
-Child item 1
-Child item 2
-Child item 3
但是子列表视图只显示一个项目(第一项),像这样
Parent Layout
- Parent ListView
- Parent Item 1
-Child item 1
- Parent Item 2
-Child item 1
- Parent Item 3
-Child item 1
- Parent Item 4
-Child item 1
如果我手动将子 ListView 的高度调整为 250dp,它会显示更多项目,但我希望子 ListView 的高度根据项目数自动换行。 我怎样才能做到这一点? (我有两个列表视图的适配器,但我不确定它是否与本次讨论相关,因此我不包括它)。
【问题讨论】:
-
在列表视图中使用可消耗的列表视图,而不是列表视图
-
@njzk2 而不是外部列表视图或嵌套列表视图或两者兼而有之?
-
而不是两者。可消耗列表视图的目的是显示列表列表。
-
@njzk2 明白了!我会在这里试一试,让你知道
-
@njzk2 很有魅力,谢谢。