标签:listview 动态 加载 lis 计算 margin set ase item
// 动态加载GridView 高度
public static void setListViewHeightBasedOnChildren(MyGridView myGridView) {
ListAdapter listAdapter = myGridView.getAdapter();
if (listAdapter == null) {
return;
}
int col = 5;
int totalHeight = 0;
for (int i = 0; i < listAdapter.getCount(); i += col) {
View listItem = listAdapter.getView(i, null, myGridView);
listItem.measure(0, 0);
totalHeight += listItem.getMeasuredHeight();
}
ViewGroup.LayoutParams params = myGridView.getLayoutParams();
params.height = totalHeight;
((MarginLayoutParams) params).setMargins(10, 10, 10, 10);
myGridView.setLayoutParams(params);
}
标签:listview 动态 加载 lis 计算 margin set ase item
原文地址:http://www.cnblogs.com/wenfei123chai/p/6048087.html