scrollView中的两个ExpandableListView

时间:2013-06-01 06:39:37

标签: android scrollview expandablelistview

我在一个活动中有两个expandableListView,首先,我把它们放在一个LinearLayout中,但是当第一个expandableListView扩展太多项目时,我看不到第二个:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    android:orientation="vertical" >

    <ExpandableListView
        android:id="@+id/myContactELV"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ExpandableListView>

    <ExpandableListView
        android:id="@+id/myGroupELV"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ExpandableListView>

</LinearLayout>

第一个视图包括组aaa,bbb,ccc,第二个视图包括ddd,eee: enter image description here

第一次展开时,第二次超出视线,屏幕不滚动: enter image description here

所以我想把它们放在一个scrollView中,但更糟糕的是:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <ExpandableListView
            android:id="@+id/myContactELV"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
        </ExpandableListView>

        <ExpandableListView
            android:id="@+id/myGroupELV"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
        </ExpandableListView>
    </LinearLayout>

</ScrollView>

enter image description here

所以,当两个expandableListview展开时,我希望清楚地看到每个项目,并且屏幕滚动。我怎样才能做到这一点?

3 个答案:

答案 0 :(得分:2)

//填充视图端口并为每个列表分配权重,以便均匀划分屏幕

 <?xml version="1.0" encoding="utf-8"?>
 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:background="@android:color/white"
   android:fillViewport="true" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:orientation="vertical"
    android:weightSum="2" >

    <ExpandableListView
        android:id="@+id/myContactELV"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" >
    </ExpandableListView>

    <ExpandableListView
        android:id="@+id/myGroupELV"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" >
    </ExpandableListView>
</LinearLayout>

</ScrollView>

答案 1 :(得分:1)

您必须单独为每个可展开列表视图提供动态高度

答案 2 :(得分:1)

scrollView中的两个ExpandableListView - 我不建议这样做,因为ExpandableListView中的子节点不会关注具有较低OS版本的少数android设备。你应该重新考虑你的设计。