전편 필요한분 여기있음~
2012/04/12 - [Android Study] - Android Custom Widget 만들기 2편
에구 삭신이야...
이제부터는 화면 그리는 것 까지는 어케 나오도록 해볼 예정임.
바로 코드 설명 갑니당.
// 초기화 함수
2012/04/12 - [Android Study] - Android Custom Widget 만들기 2편
에구 삭신이야...
이제부터는 화면 그리는 것 까지는 어케 나오도록 해볼 예정임.
바로 코드 설명 갑니당.
// 초기화 함수
private void initializeOnOffButton() {
// onTouch가 가능 하도록 설정
// onTouch가 가능 하도록 설정
this.setClickable(true);
// boolean 변수 on off 상태 값이로 이용
// boolean 변수 on off 상태 값이로 이용
mIsOn = true;
// OnOff image bitmap (리소스에서 읽어옴)
// OnOff image bitmap (리소스에서 읽어옴)
mOnOffBitMap = BitmapFactory.decodeResource(
getResources(), R.drawable.onoff_img);
// int형 on off image bitmap 크기
getResources(), R.drawable.onoff_img);
// int형 on off image bitmap 크기
mBtnHeight = mOnOffBitMap.getHeight();
mBtnWidth = mOnOffBitMap.getWidth();
// 화면 scale 얻어 오는 내용 (이미지가 풀 사이즈로 보이면 안됨)
float fscale = getContext().getResources().getDisplayMetrics().density;
// int형 변수 좌우로 움직일 수 있는 최대 크기 계산
// 여기서 MAXIMUM_WIDTH_VALUE 는 187 임
// int형 변수 좌우로 움직일 수 있는 최대 크기 계산
// 여기서 MAXIMUM_WIDTH_VALUE 는 187 임
mMovementLimite = (int) (MAXIMUM_WIDTH_VALUE * fscale);
// On 상태로 위치 조정
int left = 0;
int right = mMovementLimite;
// OnOff image rect 변수 설정
mSource = new Rect(left, 0, right, mBtnHeight);
// Display 될 rect 변수 설정
// Display 될 rect 변수 설정
mContent = new Rect(0, 0, mMovementLimite/2, mBtnHeight/2);
// Animation 효과를 주기 위한 handler
// Animation 효과를 주기 위한 handler
mHandler = new ButtonMoveHandler();
}
// 화면 크기 계산 함수
흐아~ 지친당.
자 담편에서 봅세당 ㅎㅎ
// 화면 크기 계산 함수
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// 현재 width의 mode 얻어 오기
// fill_parent, match_parent, wrap_content...
// 현재 width의 mode 얻어 오기
// fill_parent, match_parent, wrap_content...
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
// width 크기 변수
// width 크기 변수
int widthSize = 0;
// 현재 height의 mode 얻어 오기
// fill_parent, match_parent, wrap_content...
// 현재 height의 mode 얻어 오기
// fill_parent, match_parent, wrap_content...
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
// height 크기 변수
// height 크기 변수
int heightSize = 0;
// 현재 모드에 따라 크기 결졍.
switch(heightMode) {
// 값이 고정일때 예(10dp)
// 값이 고정일때 예(10dp)
case MeasureSpec.UNSPECIFIED:
heightSize = heightMeasureSpec;
break;
// wrap_content 일때
// wrap_content 일때
case MeasureSpec.AT_MOST:
heightSize = mBtnHeight/2;
break;
// fill_parent, match_parent 일때
// fill_parent, match_parent 일때
case MeasureSpec.EXACTLY:
heightSize = MeasureSpec.getSize(heightMeasureSpec);
break;
}
// 현재 모드에 따라 크기 결졍.
switch(widthMode) {
// 값이 고정일때 예(10dp)
// 값이 고정일때 예(10dp)
case MeasureSpec.UNSPECIFIED:
widthSize = widthMeasureSpec;
break;
// wrap_content 일때
// wrap_content 일때
case MeasureSpec.AT_MOST:
widthSize = mMovementLimite;
break;
// fill_parent, match_parent 일때
// fill_parent, match_parent 일때
case MeasureSpec.EXACTLY:
widthSize = MeasureSpec.getSize(widthMeasureSpec);
break;
}
// 화면 크기 등록
// 화면 크기 등록
setMeasuredDimension(widthSize, heightSize);
} 흐아~ 지친당.
자 담편에서 봅세당 ㅎㅎ
'Android' 카테고리의 다른 글
Android Custom Widget 만들기 5편 (0) | 2012.04.12 |
---|---|
Android Custom Widget 만들기 4편 (0) | 2012.04.12 |
Android Custom Widget 만들기 2편 (0) | 2012.04.12 |
Android Custom Widget 만들기 1편 (1) | 2012.04.12 |
Android Study ListView Indexer 6편 (3) | 2012.03.07 |