Authorative way to override onMeasure()?

后端 未结 8 2151
眼角桃花
眼角桃花 2020-12-04 07:32

What\'s the correct way of overriding onMeasure()? I\'ve seen various approaches. For example, Professional Android Development uses MeasureSpec to calculate the di

8条回答
  •  醉话见心
    2020-12-04 08:02

    here is how I solved the problem:

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    
            ....
    
            setMeasuredDimension( measuredWidth, measuredHeight );
    
            widthMeasureSpec = MeasureSpec.makeMeasureSpec( measuredWidth, MeasureSpec.EXACTLY );
            heightMeasureSpec = MeasureSpec.makeMeasureSpec( measuredHeight, MeasureSpec.EXACTLY);
    
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    

    }

    Moreover it was necessary for the ViewPager component

提交回复
热议问题