ListView in ScrollView

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)