Calculate the size of a list view or how to tell it to fully expand

前端 未结 12 943
小蘑菇
小蘑菇 2020-11-29 00:20

I am currently trying to use a ListView inside of a ScrollView. I know from what I\'ve read that this is looked down upon, but I\'m trying to get the ListView to expand com

12条回答
  •  离开以前
    2020-11-29 00:52

    @Override
    public void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
        if (this.isExpanded) {
            final int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
            super.onMeasure(widthMeasureSpec, expandSpec);
            final ViewGroup.LayoutParams params = this.getLayoutParams();
            params.height = this.getMeasuredHeight();
        } else {
           super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        }
    }
    

提交回复
热议问题