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