android measure and layout
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); }
posted on 2012-10-24 14:23 Jalen Wang 阅读(166) 评论(0) 编辑 收藏 举报