在ScrollView中嵌套ListView
来源:互联网 发布:linux的dd命令SD卡 编辑:程序博客网 时间:2024/06/05 19:12
只要在设置ListView的Adapter后调用此静态方法即可让ListView正确的显示在其父ListView的ListItem中。但是要注意的是,子ListView的每个Item必须是LinearLayout,不能是其他的,因为其他的Layout(如RelativeLayout)没有重写onMeasure(),所以会在onMeasure()时抛出异常。
public class Utility { public static void setListViewHeightBasedOnChildren(ListView listView) { ListAdapter listAdapter = listView.getAdapter(); if (listAdapter == null) { // pre-condition return; } int totalHeight = 0; for (int i = 0; i < listAdapter.getCount(); i++) { View listItem = listAdapter.getView(i, null, listView); listItem.measure(0, 0); totalHeight += listItem.getMeasuredHeight(); } ViewGroup.LayoutParams params = listView.getLayoutParams(); params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); listView.setLayoutParams(params); } }原文地址
0 0
- 在ScrollView中嵌套ListView
- 在ScrollView中嵌套ListView
- 在ScrollView中嵌套ListView
- 在ScrollView中嵌套ListView
- 如何在ScrollView中嵌套ListView
- 如何在ScrollView中嵌套ListView
- 总结:在ScrollView中嵌套ListView
- Android: 如何在ScrollView中嵌套ListView
- 总结:在ScrollView中嵌套ListView
- 总结:在ScrollView中嵌套ListView
- 总结:在ScrollView中嵌套ListView
- 如何在ScrollView中嵌套ListView
- 如何在ScrollView中嵌套ListView
- Android:如何在ScrollView中嵌套ListView
- 如何在ScrollView中嵌套ListView
- 如何在ScrollView中嵌套ListView
- Android -- 在ScrollView中嵌套ListView
- 千万不要在ScrollView中嵌套ListView
- jQuery获取循环出来的DOM节点
- 二级指针
- gcc 嵌入式汇编(asm)实现bsr(位扫描)指令
- HIVE函数
- 训练自己haar-like特征分类器并识别物体(3)
- 在ScrollView中嵌套ListView
- 内存区划分
- [Leetcode] Longest Consecutive Sequence
- 微信支付 for android 集成笔记( 集成遇到问题记录)
- java 校验和
- API21开始getRunningAppProcesses只返回应用本身的进程信息
- oracle数据字典
- [综合面试] 牛人整理分享的面试知识:操作系统、计算机网络、设计模式、Linux编程,数据结构总结
- Jenkins系列之—16 Maven获取Jenkins的Subversion的版本号