private void adjustListViewHeight(ListView list) {
ListAdatper adapter = list.getAdapter();
if (adapter == null) {
return;
}
int itemCount = adapter.getCount();
int totalHeight = 0;
for (int i = 0; i < itemCount; i++) {
View item = adapter.getView(i, null, list);
item.measure(0, 0);
totalHeight += item.getMeasuredHeight();
}
ViewGroup.LayoutParams params = list.getLayoutParams();
params.height = totalHeight + (list.getDividerHeight() * (itemCount - 1))
+ list.getPaddingTop() + list.getPaddingBottom();
list.setLayoutParams(params);
}
ListView in ScrollView
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 在一些初学者中很多的同学就会遇到这样的问题像标题所说的那样的问题。 什么废话我就不说了 (解释上面的代码)写个自定...
- 嵌套的GrdiView和ListView显示不全,直接重写onMessure()方法解决 ScrollView 弹...
- 老生常谈的滑动冲突问题,今天遇到与大家分享下 1、在ScrollView或ListView等滑动控件中嵌套List...
- 这个是一个老问题了,这里记录一下,供自己参考学习 首先遇到这个问题,我们肯定会思考,ListView只显示了一行,...
- 转载请标明出处: http://www.jianshu.com/p/9b6e12d8eea0本文出自:【张旭童的简...