ListView 与 GridView 在ScrollView中自适应高度
2016-03-28 17:12
363 查看
ListView
GridView
public static void setListViewHeightBasedOnChildren(ListView listView) { if (limitTimeAdapter == null) { return; } int totalHeight = 0; for (int i = 0; i < limitTimeAdapter.getCount(); i++) { View listItem = limitTimeAdapter.getView(i, null, listView); listItem.measure(0, 0); totalHeight += listItem.getMeasuredHeight(); } ViewGroup.LayoutParams params = listView.getLayoutParams(); params.height = totalHeight + (listView.getDividerHeight() * (limitTimeAdapter.getCount() - 1)); listView.setLayoutParams(params); }
GridView
public static void setGridViewHeightBasedOnChildren(GridView gridView) { if (choicenessAdapter == null) { return; } int totalHeight = 0; for (int i = 0; i < choicenessAdapter.getCount(); i += 2) { View listItem = choicenessAdapter.getView(i, null, gridView); listItem.measure(0, 0); totalHeight += listItem.getMeasuredHeight(); } ViewGroup.LayoutParams params = gridView.getLayoutParams(); params.height = totalHeight; gridView.setLayoutParams(params); }
相关文章推荐
- 完美实现Android ListView中的TextView的跑马灯效果
- android上改变listView的选中颜色
- Delphi7中Listview的常用功能汇总
- Delphi控件ListView的属性及使用方法详解
- Android编程UI设计之GridView和ImageView的用法
- android中ListView数据刷新时的同步方法
- Android提高之ListView实现自适应表格的方法
- Android中实现水平滑动(横向滑动)ListView示例
- C#中GridView动态添加列的实现方法
- C#实现ListView选中项向上或向下移动的方法
- Gridview用法大总结(全程图解珍藏版)
- C#使用RenderControl将GridView控件导出到EXCEL的方法
- asp.net gridview中用checkbox全选的几种实现的区别
- GridView使用学习总结
- asp.net 设置GridView的选中行
- 让GridView只显示特定用户的数据的方法
- GridView单元格合并
- C#导出GridView数据到Excel文件类实例
- C#与SQL连接:GridView控件对数据库的操作
- Listview加载的性能优化是如何实现的