ListView嵌套在ScrollView内显示不全的解决办法
2013-07-02 20:15
447 查看
ListView嵌套在ScrollView里面,只能够显示第一条数据。
因为ListView其实也是一个scrollView,scrollView默认是禁止嵌套的,起码导致内部的scrollView无法正确计算高度。[为什么会无法正常计算?]
解决办法也很简单,就是手动计算listView的高度并动态设置。
因为ListView其实也是一个scrollView,scrollView默认是禁止嵌套的,起码导致内部的scrollView无法正确计算高度。[为什么会无法正常计算?]
解决办法也很简单,就是手动计算listView的高度并动态设置。
public static void setListViewHeightBaseOnChildren(ListView listView) { if (listView != null) { ListAdapter adapter = listView.getAdapter(); int totalHeight = 0; int count = adapter.getCount(); for (int i = 0; i < count; i++) { //View child = listView.getChildAt(i);//crash[why?] View child = adapter.getView(i, null, listView); child.measure(0, 0); totalHeight += child.getMeasuredHeight();//有关获取一个view高度的方法? } if (count > 0) { totalHeight += (count - 1) * listView.getDividerHeight(); } LayoutParams params = listView.getLayoutParams(); params.height = totalHeight; listView.setLayoutParams(params); } }
相关文章推荐
- ListView(ScrollView)嵌套ListView、GridView显示不全,内容大于一行计算的高度不正确的解决办法
- scrollview嵌套listview,gridview 显示不全万能解决办法
- ScrollView中嵌套ListView时显示不全的问题解决办法
- 解决ScrollView下嵌套自定义ListView、GridView后依然显示不全的问题
- 解决ScrollView 嵌套 ListView GridView显示不全,以及默认不在ScrollView顶部的问题
- android ScrollVIew中嵌套GridView,和ListView显示不全解决方法
- ScrollView嵌套ListView,GridView,RecyclerView以及RecyclerView嵌套RecyclerView显示不全的解决方法
- ScrollView中嵌套ListView造成ListView高度只显示一行解决办法
- android ScrollView中嵌套GridView,ListView只显示一行的解决办法
- ScrollView嵌套ListView,Listview条目显示不全解决方法(嵌套GridVeiw同理)
- 关于6.0ScrollView嵌套RecyclerView高度不正确显示不全问题解决办法
- [Android] 在ScrollView 中嵌套 GridView/ListView时只显示一行的原因和解决办法
- [原] 解决在ScrollView中嵌套ListView或ExpandableListView时显示不全的问题
- ListView嵌套GridView,显示不全解决办法
- ScrollView中嵌套GridView,ListView只显示一行的解决办法
- ListView嵌套在ScrollView中,只显示一行的解决办法
- ScrollView中嵌套GridView,ListView只显示一行的解决办法
- 【Android基础学习】动态设置 listView的高度,解决scrollView中嵌套listview时显示不全的问题
- android ScrollView中嵌套GridView,ListView只显示一行的解决办法
- Android ScrollView嵌套ListView,ListView只显示一行或不显示的解决办法