隐藏列表视图没有显示所有元素 [英] hidden listview not showing all elements
问题描述
我具有其中有打开和关闭的一些额外信息一些标签的布局。其中的一个标记,显示了一个列表视图。但是,而不是显示所有的元素,它仅显示一个接一个带滚动功能。我只是想表明在ListView中的所有项目。
在屏幕的正常状态:
http://i39.tinypic.com/2n1baq1.png
点击标签之后:
http://i41.tinypic.com/2dvliqq.png
这是屏幕的关键XML:
<的TextView
机器人:ID =@ + ID / tv_school
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignLeft =@ + ID / tv_basic
机器人:layout_below =@ + ID / divider3a
机器人:paddingBottom会=10dip
机器人:paddingTop =10dip
机器人:文字=学校信息
机器人:文字颜色=#5E5E60
安卓的onClick =animationText
机器人:可点击=真/> < ImageView的
机器人:ID =@ + ID / uparrow3
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentRight =真
机器人:layout_below =@ + ID / divider3a
机器人:layout_above =@ + ID / divider3b
机器人:layout_marginRight =10dip
机器人:layout_marginTop =10dip
机器人:layout_marginBottom =10dip
机器人:SRC =@绘制/向上
机器人:知名度=隐形/> < ImageView的
机器人:ID =@ + ID / downarrow3
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentRight =真
机器人:layout_below =@ + ID / divider3a
机器人:layout_above =@ + ID / divider3b
机器人:layout_marginRight =10dip
机器人:layout_marginTop =10dip
机器人:layout_marginBottom =10dip
机器人:SRC =@绘制/下/> < ImageView的
机器人:ID =@ + ID / divider3b
机器人:layout_width =match_parent
机器人:layout_height =1DP
机器人:layout_below =@ + ID / tv_school
机器人:知名度=隐形
机器人:背景=@机器人:彩色/ darker_gray/> < ListView控件
机器人:ID =@ + ID / lv_schoolinfo
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_below =@ + ID / divider3b
机器人:layout_alignLeft =@ + ID / tv_basic
机器人:paddingBottom会=10dip
机器人:paddingTop =10dip
机器人:paddingRight =10dip
机器人:滚动条=无
机器人:方向=垂直
机器人:知名度=隐形/>
< ImageView的
机器人:ID =@ + ID / divider4
机器人:layout_width =match_parent
机器人:layout_height =1DP
机器人:layout_below =@ + ID / tv_school
机器人:背景=@机器人:彩色/ darker_gray/>
这是适配器的code:
的ListView列表=(ListView控件)findViewById(R.id.lv_schoolinfo);
ArrayList的<&参数GT; PARAMS = l.getSchools();
ArrayList的<串GT;学校=新的ArrayList<串GT;();
的for(int i = 0; I< params.size();我++){
schools.add(params.get(ⅰ).getName());
}
ArrayAdapter<串GT;适配器=新ArrayAdapter<串GT;(这一点,android.R.layout.simple_list_item_1,学校);
list.setAdapter(适配器);
使用这个类公用事业
公共类工具
{
公共静态无效setListViewHeightBasedOnChildren(ListView控件ListView控件)
{
ListAdapter listAdapter = listView.getAdapter();
如果(listAdapter == NULL)
{
返回;
}
INT totalHeight = 0;
INT desiredWidth = MeasureSpec.makeMeasureSpec(listView.getWidth(),MeasureSpec.AT_MOST);
的for(int i = 0; I< listAdapter.getCount();我++)
{
查看的listItem = listAdapter.getView(I,空,ListView控件);
listItem.measure(desiredWidth,MeasureSpec.UNSPECIFIED);
totalHeight + = listItem.getMeasuredHeight();
}
ViewGroup.LayoutParams PARAMS = listView.getLayoutParams();
params.height = totalHeight +(listView.getDividerHeight()*(listAdapter.getCount() - 1))+ 20;
listView.setLayoutParams(PARAMS);
listView.requestLayout();
}
}
和使用这个类里面像这样
list1.setAdapter(imageAdapteritem);
Utility.setListViewHeightBasedOnChildren(list1的);
这将扩大您的列表,以孩子的总数您可以同时查看所有的人:)
I have a layout in which there are some tags that opens and closes some extra information. One of these tags, shows a listview. But instead of showing all the elements, it shows just one by one with scrolling enabled. I just want to show all the items in the listview.
Normal state of the screen:
http://i39.tinypic.com/2n1baq1.png
After clicking on the tag:
http://i41.tinypic.com/2dvliqq.png
This is the critical xml of the screen:
<TextView
android:id="@+id/tv_school"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/tv_basic"
android:layout_below="@+id/divider3a"
android:paddingBottom="10dip"
android:paddingTop="10dip"
android:text="School Info"
android:textColor="#5E5E60"
android:onClick="animationText"
android:clickable="true" />
<ImageView
android:id="@+id/uparrow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/divider3a"
android:layout_above="@+id/divider3b"
android:layout_marginRight="10dip"
android:layout_marginTop="10dip"
android:layout_marginBottom="10dip"
android:src="@drawable/up"
android:visibility="invisible" />
<ImageView
android:id="@+id/downarrow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/divider3a"
android:layout_above="@+id/divider3b"
android:layout_marginRight="10dip"
android:layout_marginTop="10dip"
android:layout_marginBottom="10dip"
android:src="@drawable/down" />
<ImageView
android:id="@+id/divider3b"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@+id/tv_school"
android:visibility="invisible"
android:background="@android:color/darker_gray"/>
<ListView
android:id="@+id/lv_schoolinfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/divider3b"
android:layout_alignLeft="@+id/tv_basic"
android:paddingBottom="10dip"
android:paddingTop="10dip"
android:paddingRight="10dip"
android:scrollbars="none"
android:orientation="vertical"
android:visibility="invisible" />
<ImageView
android:id="@+id/divider4"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@+id/tv_school"
android:background="@android:color/darker_gray"/>
And this is the code of the adapter:
ListView list = (ListView) findViewById(R.id.lv_schoolinfo);
ArrayList<Param> params = l.getSchools();
ArrayList<String> schools = new ArrayList<String>();
for(int i=0; i<params.size(); i++){
schools.add(params.get(i).getName());
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, schools);
list.setAdapter(adapter);
Use this class as utility
public class Utility
{
public static void setListViewHeightBasedOnChildren(ListView listView)
{
ListAdapter listAdapter = listView.getAdapter();
if (listAdapter == null)
{
return;
}
int totalHeight = 0;
int desiredWidth = MeasureSpec.makeMeasureSpec(listView.getWidth(), MeasureSpec.AT_MOST);
for (int i = 0; i < listAdapter.getCount(); i++)
{
View listItem = listAdapter.getView(i, null, listView);
listItem.measure(desiredWidth, MeasureSpec.UNSPECIFIED);
totalHeight += listItem.getMeasuredHeight();
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1))+20;
listView.setLayoutParams(params);
listView.requestLayout();
}
}
and use this classs like this
list1.setAdapter(imageAdapteritem);
Utility.setListViewHeightBasedOnChildren(list1);
this will expand your list to the total number of childs you can view all of them at same time :)
这篇关于隐藏列表视图没有显示所有元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!