美文网首页
ListView in ScrollView

ListView in ScrollView

作者: 乐此不痞 | 来源:发表于2017-09-30 13:52 被阅读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);
    }
    

    相关文章

      网友评论

          本文标题:ListView in ScrollView

          本文链接:https://www.haomeiwen.com/subject/dswgextx.html