列表视图不滚动

时间:2014-01-24 18:44:10

标签: android android-listview scroll click

我有一个包含可扩展卡片的列表视图。每张卡片有2个帧视图,一个用于未展开的视图,另一个用于展开的视图。在展开的视图中,我有另一个列表视图 - 不滚动。谁能告诉我为什么?这是一些代码:

第一个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>

第二个列表视图(扩展卡内容):

<?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 个答案:

答案 0 :(得分: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具有良好的布局呈现效果在需要时启用滚动。