// 动态加载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);
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-09
  • 2021-11-19
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案