2014-01-24 139 views
0

我有一個列表視圖,其中包含可擴展卡。每張卡片有兩個框架視圖,一個用於展開視圖,另一個用於展開視圖。在擴展視圖中,我有另一個listview - 不滾動。誰能告訴我爲什麼?下面是一些代碼:Listview not scrolling

首先列表視圖:

<LinearLayout 
     android:background="@null" 
     android:id="@+id/contentLayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" > 

     <ListView 
      android:id="@+id/groups_listview" 
      android:layout_width="match_parent" 
      android:divider="@null" 
      android:layout_height="wrap_content" > 
     </ListView> 
    </LinearLayout> 

第二列表視圖(擴展卡內容):

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:bootstrapbutton="http://schemas.android.com/apk/res-auto" 
    xmlns:fontawesometext="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/activity_expandablelistitem_card_title" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/corners_white_transparent" 
    android:orientation="vertical" > 

    <ListView 
     android:id="@+id/friendsInGroupListview" 
     android:layout_width="match_parent" 
     android:layout_height="200dp" 
     android:divider="@null" > 
    </ListView> 

</LinearLayout> 

擴展卡:

<?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="wrap_content" 
    android:orientation="vertical" 
    android:descendantFocusability="blocksDescendants" 
    android:padding="16dp" > 

    <FrameLayout 
     android:id="@+id/activity_expandablelistitem_card_title" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 
    </FrameLayout> 

    <FrameLayout 
     android:id="@+id/activity_expandablelistitem_card_content" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="4dp" > 
    </FrameLayout> 

</LinearLayout> 

回答

1

我從來沒有使用wrap_contentlayout_height也不layout_width,它會導致性能問題,一你可以閱讀here。同時設置靜態寬度/高度不是一個好主意,因爲它可能會導致幾個設備中的佈局問題。

說,我總是定義我ListView就像這樣:

<ListView 
    android:id="@+id/who_list" 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:scrollbars="vertical"> 
</ListView> 

設置你的layout_weight一個LinearLayout,內帶只是這個視圖中,你讓自己確信ListView將有一個良好的佈局呈現並且它會在需要時啓用滾動。