简体   繁体   中英

Listview not scrolling

I have a listview that holds expandable cards. Each card is 2 frame views, one for the un-expanded view and one for the expanded view. In the expanded view I have another listview - that doesn't scroll. Can anyone tell me why? Here's some code:

First listview:

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

2nd listview (Expanded Card Content):

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

Expandable card:

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

I'd never use wrap_content in the layout_height nor layout_width , it causes performance issues, as you may read here . Also setting a static width/height is not a good idea as it may lead to layout issues in several devices.

Said that, I always define my ListView s like this:

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

Setting your layout_weight within a LinearLayout with just this view inside it , you make yourself sure that ListView will have a good layout rendering and it will enable scrolling when needed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM