[英]Listview not scrolling
我有一個可擴展卡的列表視圖。 每張卡有2個框架視圖,一個用於非展開視圖,一個用於展開視圖。 在展開的視圖中,我還有另一個列表視圖-不會滾動。 誰能告訴我為什么? 這是一些代碼:
第一個列表視圖:
<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>
我從來沒有使用wrap_content
在layout_height
也不layout_width
,它會導致性能問題,因為你可以閱讀這里 。 設置靜態寬度/高度也不是一個好主意,因為它可能導致多個設備的布局問題。
話雖如此,我總是這樣定義ListView
:
<ListView
android:id="@+id/who_list"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scrollbars="vertical">
</ListView>
在LinearLayout
中僅使用此視圖設置您的layout_weight
,您可以確保ListView
具有良好的布局渲染,並在需要時啟用滾動。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.