[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);
}

이 블로그의 인기 게시물

좌표 변환: 회전 이동

Unmappable character for encoding MS949

HTTP POST