안드로이드 개발 질문/답변
(글 수 45,052)
첨부한 Pic그림 또는 아래의 xml코드를 보다시피 제가 위 아래로 버튼을 담은 리니어 레이아웃을 만들고 중간에 Absolute레이아웃과 비슷한 레이아웃을 만들어 그안에 버튼을 움직이는 프로그램을 만들고 있습니다.
그런데 문제는 제가 버튼을 움직일 때
LayoutParam 을 이용하여 움직이는데 제가 설정한 값과 조금 다른 값이 들어가서 질문을 올립니다.
아래와 같은 코드에서 저는 중앙 레이아웃내에서 마우스클릭한 좌표를 알아내려고
getRawY를 이용하여 얻은 값에 위쪽 레이아웃 크기인 106 + a을 빼준 값(106은 버튼크기100 + 위아래 마진 6이고 a는 getY를 통해 버튼 내 클릭한 위치)을 현재 중앙 레이아웃의 좌표값으로 하고 이 값을 LayoutParam으로 해서 버튼의 위치를 지정하고 있는데 이상하게 버튼의 위치를 지정하면 본래 값보다 76픽셀 더 높은 값으로 버튼의 좌표값이 잡혀 현재 76픽셀을 더 빼줘야 제 마우스가 클릭한 지점에 버튼이 이동하게 됩니다.
즉 식으로 하면
중앙 레이아웃내 내가 클릭해 버튼을 이동시키고 싶은 좌표 =
getRawY - 위쪽 레이아웃의 총크기 - 해당 버튼내 내가 클릭한 좌표 - 76(왜 이값을 빼줘야 하는지 모름) 입니다.
여기서 왜 제가 76을 빼줘야 하는지 정말 모르겠습니다. 여기서 나온 76이 대체 어디서 나온 값일까요?
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!--상단 버튼 부분-->
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="80px">
<Button
android:layout_width="0px"
android:layout_height="80px"
android:layout_weight="1"
android:text="All Hold"
android:id="@+id/allholdbtn"/>
<Button
android:layout_width="0px"
android:layout_height="80px"
android:layout_weight="1"
android:text="All UnHold"
android:id="@+id/allunholdbtn"/>
</LinearLayout>
<!--중단 게임 뷰 부분-->
<game.PushPangProto.PushPangGameLayout
android:layout_width="fill_parent"
android:layout_height="300dp"
android:id="@+id/whole_gameview">
</game.PushPangProto.PushPangGameLayout>
<!--하단 버튼 부분-->
<LinearLayout
android:orientation="horizontal"
android:layout_gravity="bottom"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Hold"
android:id="@+id/holdbtn"/>
<Button
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="UnHold"
android:id="@+id/unholdbtn"/>
</LinearLayout>
</LinearLayout>
</FrameLayout>




음 어떤걸 클릭하는지 모르겠는데.
보통 76은 내가 클릭한 객체의 크기더라구요. 아마 버튼 높이 일껄요?