[英]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. 每张卡有2个框架视图,一个用于非展开视图,一个用于展开视图。 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 . 我从来没有使用wrap_content
在layout_height
也不layout_width
,它会导致性能问题,因为你可以阅读这里 。 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
:
<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. 在LinearLayout
中仅使用此视图设置您的layout_weight
,您可以确保ListView
具有良好的布局渲染,并在需要时启用滚动。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.