public class LvHeightUtil {
/**
* 解决listView和scrollView的共存问题
* @param listView
*/
public static void setListViewHeightBasedOnChildren(ListView listView) {
ListAdapter listAdapter = listView.getAdapter();
if (listAdapter == null) {
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);
}
}
//
// OrdersProductAdapter productAdapter = new
// OrdersProductAdapter(data.get(position)
// .getOrderProductList(), context);
// // holder.lv.setAdapter(productAdapter);
// // LvHeightUtil.setListViewHeightBasedOnChildren(holder.lv);
解决listView和scrollView的共存问题
最新推荐文章于 2021-10-06 16:02:22 发布