在Android上滚动型的问题里面的ListView [英] ListView inside a ScrollView issue in Android
问题描述
下面是我的XML布局。我有我的滚动型里面的列表视图。我手动设置的高度,如果我改变列表视图高度WRAP_CONTENT它不工作。而且如果数据增长超过它隐藏的限制。我看到很多答案来解决这一点。什么是解决它为我的情况下,最好的选择?
<?XML版本=1.0编码=UTF-8&GT?;
<滚动型的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT><的LinearLayout
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:layout_weight =1
机器人:focusableInTouchMode =真正的> <的LinearLayout
机器人:ID =@ + ID / store_scroller
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:方向=垂直> < RelativeLayout的
机器人:layout_width =match_parent
机器人:layout_height =45dp
机器人:背景=#c6c6c6
机器人:填充=10dp> <的TextView
机器人:ID =@ + ID / textView1
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
layout_alignParentLeft =真
机器人:文字=专卖店
机器人:TEXTSIZE =20dp/> <的TextView
机器人:ID =@ + ID / merchant_count_textView
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentRight =真
机器人:文字=0结果/>
< / RelativeLayout的>
<画廊
机器人:ID =@ + ID / gallery1
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:drawSelectorOnTop =真
机器人:重力=左
机器人:listSelector =@彩色/ gridviewlistselector
机器人:paddingLeft =10dp
机器人:paddingRight =20dp
机器人:paddingTop =10dp
机器人:间距=10dp/> < RelativeLayout的
机器人:layout_width =match_parent
机器人:layout_height =55dp
机器人:背景=#c6c6c6
机器人:填充=10dp> <的TextView
机器人:ID =@ + ID / textView1
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
layout_alignParentLeft =真
机器人:文字=产品
机器人:TEXTSIZE =20dp/> <微调
机器人:ID =@ + ID / filter_spinner
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginLeft =40dp
机器人:layout_toRightOf =@ + ID / textView1/> <的TextView
机器人:ID =@ + ID / product_count_textView
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentRight =真
机器人:文字=0结果/>
< / RelativeLayout的> < ListView控件
机器人:ID =@ + ID /列表
机器人:layout_width =FILL_PARENT
机器人:layout_height =4800dp
机器人:layout_weight =1
机器人:drawSelectorOnTop =真
机器人:listSelector =@彩色/ gridviewlistselector
机器人:方向=垂直/>
< / LinearLayout中>
< / LinearLayout中>< /滚动型>
简短的回答:你不能(也不应该)有一个包裹的ListView
在滚动型
。
龙答:由于罗曼盖伊(UI导师在谷歌自己)曾经说过:
使用一个ListView使它不滚动是极其昂贵和违背的ListView的全部目的。你不应该这样做。只需使用一个的LinearLayout来代替。
块引用>报价通过我怎样才能把一个ListView成滚动型没有它崩溃?。
Here is my XML layout. I have a list view inside my scrollview. I am setting the height manually if I change the listview height to wrap_content it is not working. And also if the data grows beyond the limit it is hiding. I am seeing many answers to solve this. What is the best option to solve it for my case?
<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:focusableInTouchMode="true" > <LinearLayout android:id="@+id/store_scroller" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <RelativeLayout android:layout_width="match_parent" android:layout_height="45dp" android:background="#c6c6c6" android:padding="10dp" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" layout_alignParentLeft="true" android:text="Stores" android:textSize="20dp" /> <TextView android:id="@+id/merchant_count_textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:text="0 Results" /> </RelativeLayout> <Gallery android:id="@+id/gallery1" android:layout_width="match_parent" android:layout_height="wrap_content" android:drawSelectorOnTop="true" android:gravity="left" android:listSelector="@color/gridviewlistselector" android:paddingLeft="10dp" android:paddingRight="20dp" android:paddingTop="10dp" android:spacing="10dp" /> <RelativeLayout android:layout_width="match_parent" android:layout_height="55dp" android:background="#c6c6c6" android:padding="10dp" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" layout_alignParentLeft="true" android:text="Products" android:textSize="20dp" /> <Spinner android:id="@+id/filter_spinner" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="40dp" android:layout_toRightOf="@+id/textView1" /> <TextView android:id="@+id/product_count_textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:text="0 Results" /> </RelativeLayout> <ListView android:id="@+id/list" android:layout_width="fill_parent" android:layout_height="4800dp" android:layout_weight="1" android:drawSelectorOnTop="true" android:listSelector="@color/gridviewlistselector" android:orientation="vertical" /> </LinearLayout> </LinearLayout> </ScrollView>
解决方案Short answer: You can't (shouldn't) have a
ListView
wrapped in aScrollView
.Long answer: As Romain Guy (UI-guru at Google themselves) once said:
Using a ListView to make it not scroll is extremely expensive and goes against the whole purpose of ListView. You should NOT do this. Just use a LinearLayout instead.
Quote via "How can I put a ListView into a ScrollView without it collapsing?".
这篇关于在Android上滚动型的问题里面的ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!