안드로이드 레이아웃 크기 변환 관련
함수 : onMeasure
도중에 레이아웃 크기를 바꾸어야 할경우 보통 setWidth나 setHeight 가 없고 독특하게 onMeasure 함수에서
크기를 설정해 주게 셋팅해야 한다.
public void onMeasure(int widthMeasureSpec,int heightMeasureSpec)
{
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
//////////////////////////////////////////////////ex code http://202psj.tistory.com
... user code
...
setMeasuredDimension(w, h); //이 함수를 이용하거나 다른 width, height 를 설정해준다,
}
///////////////////////////////////////////////////////////////////////////////////////////
안드로이드 레이아웃 변환된 크기 확인, 변환후 셋팅
함수: onLayout
레이아웃이 셋팅후 크기를 알아야 하는데 (예) fill_parent 셋팅전에 가로세로 크기가 0, 0 이렇게 나오므로)
이 함수를 거치면 변환후 크기를 알수가 있다.
View _saveLayout; // 여기에 설정할 레이아웃을 넣어둔다.
public void onLayout(boolean changed, int left, int top, int right, int bottom)
{
super.onLayout(changed, left, top, right, bottom);
//////////////////////////////////////ex code http://202psj.tistory.com
int w = _saveLayout .getWidth();
int h = _saveLayout.getHeight();
_screen_w = _v.getWidth();
_screen_h = _v.getHeight();
}
위의 방식으로 변환후 값이 나오기 때문에 값을 보구 유저가 셋팅을 할수가 있다.
onMeasure, onLayout 이 두개가 변환후 근처의 루프에서 이벤트가 가므로 두개 모두 비슷한
용도로 쓰일수도 있다.
'구글과인터넷 > 안드로이드' 카테고리의 다른 글
안드로이드 웹뷰에서 꽉찬 화면, 크기조정 관련~ (0) | 2012.12.12 |
---|---|
안드로이드 키입력,터치입력 관련 (방향키입력, 위치이동키 등등) (0) | 2012.12.12 |
전체화면 사용하기 (Status bar, Title bar 숨기기) 타이틀바 높이 확인 (0) | 2012.12.12 |