android measure and layout

How android draws views?

Measure + layout

When do the layout, we need translate the position to the parent space.

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        
        mSpeedSelector.measure(widthMeasureSpec, heightMeasureSpec);
        
        int width = mSpeedSelector.getMeasuredWidth();
        int height = mSpeedSelector.getMeasuredHeight();
        
        this.setMeasuredDimension(width, height);
    }

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        // Translate the position to the parent space
        mSpeedSelector.layout(0, 0, r - l, b - t);
    }

转载于:https://www.cnblogs.com/jalenwang/archive/2012/10/24/android-view.html

猜你喜欢

转载自blog.csdn.net/weixin_34289454/article/details/93939376