안드로이드 개발 질문/답변
(글 수 45,052)
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#747170" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<include
android:id="@+id/VIEWER_TITLE"
layout="@layout/include_title" />
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.customView></com.customView>
....
....
위와 같은 구조의 Xml 사용해서 화면을 그렸을때
customView의 top 의 좌표값을 알고 싶습니다.
getTop()을 사용하면 0
getParent()).getTop()을 사용하면 ->68
debug 모드로 this.mTop 변수 값을 보면 ->106
(여기서 this는 customView 객체를 말합니다.)
0, 68, 106 여기서 제가 원하는 올바른 값은 106인데..
View.getTop() 으로는 얻을 수 없더군요..
답변 부탁드립니다.
[참고]
Android OS 2.2 버전에서 나타나는 현상입니다.
Android OS 3.1 버전에서 테스트했을 경우 getParent()).getTop() == this.mTop 입니다.
getTop, getBottom 등은 해당 레이아웃이 화면에 배치된 후에 사용해야 제대로 값을 가져올수 있습니다. (VISIBLE 또는 INVISIBLE상태)
onCreate에서 바로 getTop하지 마시고 버튼 하나 만들어서 해당버튼 클릭했을 때 costomView의 getTop을 구해보세요 제대로 나올겁니다.