ListView中嵌套ListView是,嵌套在里面的ListView不能完全显示解决方法
来源:互联网 发布:php银联支付 编辑:程序博客网 时间:2024/05/18 03:44
在设置完ListView的Adapter后,根据ListView的子项目重新计算ListView的高度,然后把高度再作为LayoutParams设置给ListView,这样它的高度就正确了,以下是源码: 只要在设置ListView的Adapter后调用此静态方法即可让ListView正确的显示在其父ListView的ListItem中。但是要注意的是,子ListView的每个Item必须是LinearLayout,不能是其他的,因为其他的Layout(如RelativeLayout)没有重写onMeasure(),所以会在onMeasure()时抛出异常。
- public class Utility {
- public static void setListViewHeightBasedOnChildren(ListView listView) {
- // 获取ListView对应的Adapter
- ListAdapter listAdapter = listView.getAdapter();
- if(listAdapter == null) {
- return;
- }
- int totalHeight = 0;
- for(int i = 0, len = listAdapter.getCount(); i < len; i++) { // listAdapter.getCount()返回数据项的数目
- View listItem = listAdapter.getView(i, null, listView);
- listItem.measure(0, 0); // 计算子项View 的宽高
- totalHeight += listItem.getMeasuredHeight(); // 统计所有子项的总高度
- }
- ViewGroup.LayoutParams params = listView.getLayoutParams();
- params.height = totalHeight
- + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
- // listView.getDividerHeight()获取子项间分隔符占用的高度
- // params.height最后得到整个ListView完整显示需要的高度
- listView.setLayoutParams(params);
- }
- }
0 0
- ListView中嵌套ListView是,嵌套在里面的ListView不能完全显示解决方法
- ScrollView中嵌套ListView是,嵌套在里面的ListView不能完全显示解决方法
- ScrollView中嵌套ListView是,嵌套在里面的ListView不能完全显示解决方法
- ScrollView中嵌套ListView是,嵌套在里面的ListView不能完全显示解决方法
- ScrollView中嵌套的ListView不能完全显示解决方法
- ScrollView嵌套ListView时,ListView不能完全显示解决方法
- ListView嵌套GridView,Gridview不能完全显示
- 在ScrollView中嵌套ListView,ListView无法完全显示
- Android4.x中ScrollView嵌套ListView,ListView不能完全显示总结、解决办法
- ScrollView中嵌套ListView中ListView中显示不全解决方法
- android listview嵌套Listview不能显示全部内容
- ListView头部嵌套ListView显示不全解决方法
- ExpandableListView嵌套ListView导致ListView不能完全显示数据的问题
- listView中嵌套GridView不能完整显示的解决办法
- ListView中嵌套ListView
- ListView中嵌套listView
- ListView中嵌套ListView
- ListView中嵌套ListView
- 调用函数求特殊三位数
- java中final修饰符用法
- UIApplication详解(转载)
- poj 3252 Round Numbers (组合数学)
- "XX cannot be resolved to a type "eclipse报错及解决说明
- ListView中嵌套ListView是,嵌套在里面的ListView不能完全显示解决方法
- java中继承和多态区别. -编辑
- Android AIDL使用方法详解
- the schema version of 'microsoft.aspnet.mvc' is incompatible with version of nuget
- android系统数据库
- uploadify 3.2.1+spring mvc上传文件
- Opencl 第一节
- Lua 语法学习记录一
- 继承与派生