2013-06-01 31 views
2

我有兩個expandableListView活動中,起初,我把他們的LinearLayout裏面,但是當第expandableListView擴大太多的項目,我不能看到第二內側:兩個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

所以我想將它們放在一個滾動視圖,而且更糟糕:

<?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擴大,我想清楚地看到每一個項目,並在屏幕滾動。我怎麼能做到這一點?

+0

描述使用兩個ELV的原因。 –

+0

這兩個ELV應該有不同的數據源,適配器和不同的含義。這裏的數據是爲了簡單,它們不是真實的。 – cameron

+0

你是什麼意思?滾動視圖中的 –

回答

1

你必須給每一個擴展列表視圖的動態高度分別

2

//填寫視口,並指定waight每個列表中,這樣devide屏幕均勻

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

設置屬性fillViewport爲true。 Linearlayout中的 爲兩部分中的分屏顯示分配權重總和。 我希望它能正常工作 –

+0

我會試試看。謝謝。 – cameron

1

兩個滾動視圖內ExpandableListView - 我不會推薦這麼做,因爲ExpandableListView中的子項目不會專注於操作系統版本較低的少數Android設備。你應該重新考慮你的設計。