[View] onMeasure
특별한 경우가 아니라면 다음의 onMeasure함수를 그대로 적용해도 무방하다.
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int wMode, hMode, wSpec, hSpec;
int width=320, height=320;
wMode = MeasureSpec.getMode(widthMeasureSpec);
hMode = MeasureSpec.getMode(heightMeasureSpec);
wSpec = MeasureSpec.getSize(widthMeasureSpec);
hSpec = MeasureSpec.getSize(heightMeasureSpec);
switch(wMode) {
case MeasureSpec.AT_MOST:
width = wSpec;
break;
case MeasureSpec.EXACTLY:
width = wSpec;
break;
case MeasureSpec.UNSPECIFIED:
break;
}
switch(hMode) {
case MeasureSpec.AT_MOST:
height = hSpec;
break;
case MeasureSpec.EXACTLY:
height = hSpec;
break;
case MeasureSpec.UNSPECIFIED:
break;
}
setMeasuredDimension(width, height);
}
댓글
댓글 쓰기