2
votes

I have two expandableListView inside an activity, At first, i put them inside a LinearLayout, but when the first expandableListView expands too much item, i cannot see the second:

<?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>

The first view include group aaa,bbb,ccc and the second include ddd, eee: enter image description here

When the first expand, the second is beyond sight,and the screen doesn't scroll: enter image description here

So i want to put them in a scrollView, but even worse:

<?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

So, when the two expandableListview expand, i want to see every item clearly, and the screen scroll. How can i achieve that?

3
Describe the reason for using two ELVs. - MaciejGórski
The two ELVs should have different data source , adapters, and different meanings. The data here is for simplicity, they are not real. - cameron
What different meanings do you mean? - MaciejGórski
at least answer the damn question @MaciejGórski - Jacob Sánchez

3 Answers

2
votes

// fill view port and assign waight to each list so that devide screen evenly

 <?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
votes

You Have to give dynamic height of every expandable list view separately

1
votes

Two ExpandableListView inside a scrollView - I will not recommend that, because children in ExpandableListView will not get focus on few android devices having lower OS versions. You should reconsider your design.