Android 可扩展ListView在子布局内不工作
可展开的Listview直接放在活动的根RelativeLayout中可以正常工作。但我需要将它放置在一个由滚动视图包装的子相对布局中。但当我们这样做时,只显示组标题,在可展开列表中没有子项Android 可扩展ListView在子布局内不工作,android,android-layout,listview,android-listview,expandablelistview,Android,Android Layout,Listview,Android Listview,Expandablelistview,可展开的Listview直接放在活动的根RelativeLayout中可以正常工作。但我需要将它放置在一个由滚动视图包装的子相对布局中。但当我们这样做时,只显示组标题,在可展开列表中没有子项 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="mat
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.computan.carcal.CourtesyCarDetailActivity">
<include
android:id="@+id/app_toolbar_view"
layout="@layout/apptoolbar"></include>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/app_toolbar_view"
>
**<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
>**
<android.support.v7.widget.CardView
android:id="@+id/cardView"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/courtesyVehicleExpandableListView"
android:layout_gravity="top"
android:padding="20dp"
card_view:cardBackgroundColor="@color/PrimaryBackgroundColor"
card_view:cardCornerRadius="4dp"
card_view:cardElevation="4dp"
card_view:cardUseCompatPadding="true"
card_view:contentPadding="10dp"
>
<!-- cardview code omitted for clarity -->
</android.support.v7.widget.CardView>
**<ExpandableListView
android:id="@+id/courtesyVehicleExpandableListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/app_toolbar_view"
android:layout_marginTop="8dp"
android:divider="#A4C739"
android:dividerHeight="0.5dp"
android:indicatorLeft="?android:attr/expandableListPreferredItemIndicatorLeft"/>**
</RelativeLayout>
</ScrollView>
</RelativeLayout>
为了简单起见,我没有发布适配器和数据获取代码。上述代码不显示组信息,但不显示组中的任何项目。如果我将可展开的listview直接放在根相对布局中。它工作正常,但我需要滚动条。这是工作代码
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.computan.carcal.CourtesyCarDetailActivity">
<include
android:id="@+id/app_toolbar_view"
layout="@layout/apptoolbar"></include>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/app_toolbar_view"
>
**<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
>**
<android.support.v7.widget.CardView
android:id="@+id/cardView"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/courtesyVehicleExpandableListView"
android:layout_gravity="top"
android:padding="20dp"
card_view:cardBackgroundColor="@color/PrimaryBackgroundColor"
card_view:cardCornerRadius="4dp"
card_view:cardElevation="4dp"
card_view:cardUseCompatPadding="true"
card_view:contentPadding="10dp"
>
</android.support.v7.widget.CardView>
</RelativeLayout>
</ScrollView>
**<ExpandableListView
android:id="@+id/courtesyVehicleExpandableListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/app_toolbar_view"
android:layout_marginTop="8dp"
android:divider="#A4C739"
android:dividerHeight="0.5dp"
android:indicatorLeft="?android:attr/expandableListPreferredItemIndicatorLeft"/>**
</RelativeLayout>
正如您将其放置在scrollview和内部相对布局外部后所看到的,代码工作正常,并在其下显示组和项目
这是Expandable Listview的默认行为,还是任何人都可以指导我在子相对布局中使用Listview时如何获取组项目?ScrollView+Expandable Listview=糟糕的设计。感谢您的及时回复,我们有一个显示大量静态信息的cardview,还有一个显示一些用户选择的可扩展ListView。信息的扩展超过了屏幕,所以我们不得不添加一个滚动视图。可扩展/列表视图已经包含了一个滚动机制。