ListView in ScrollView

2017-09-30  本文已影响0人  乐此不痞
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);
}
上一篇下一篇

猜你喜欢

热点阅读