2013-06-13 1 views
2

나는 아래 그림과 같은 레이아웃을 디자인 할 :안드로이드에서 한 레이아웃에 버튼 반을, 다른 레이아웃에 반을 표시하는 방법은 무엇입니까?

enter image description here

나는 상대 레이아웃을 사용하여 그것을 할 시도했지만 나는 해결책을 마련하지 않았다. 모든 장치 화면에서 동일한 위치에 있어야합니다. 나는 그것을 어떻게 성취 할 수 있는가 ??? 다음 코드를 사용해 보았습니다.

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <RelativeLayout 
     android:id="@+id/relative_layout_top" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/obaz" > 

    </RelativeLayout> 

    <RelativeLayout 
     android:id="@+id/relative_layout_bottom" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/relative_layout_top" 
     android:background="@drawable/obaz2" > 

     <Button 
      android:id="@+id/bt_atoz" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentTop="true" 
      android:layout_marginTop="-20dp" 

      android:background="@drawable/button_active" /> 

    </RelativeLayout> 

</RelativeLayout> 

제안 사항을 보내주십시오.

+2

2 아이 뷰와 1 주 기준으로 레이아웃 중력 가운데 버튼을 center_vertical 및 기타 2 (어린이 2 위에 가진 & 아래) 부모 FrameLayout이를 사용해보십시오 당신이 원하는 정렬 –

+1

^이 답변입니다. –

+0

정답 일지 모르지만 문제는 응답하지 않습니다. 즉, 장치를 hdpi에서 xdpi로 변경하면 작동하지 않습니다. – androidcodehunter

답변

-2

RelativeLayout relative_layout_bottom 외부에 Button 선언을 넣은 다음 원하는 곳에 배치 할 수 있습니다. 예를 들어

: 편집 :

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <RelativeLayout 
     android:id="@+id/relative_layout_top" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/obaz" > 
    </RelativeLayout> 

    <Button 
     android:id="@+id/bt_atoz" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_centerVertical="true" 
     android:background="@drawable/button_active" /> 

    <RelativeLayout 
     android:id="@+id/relative_layout_bottom" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/relative_layout_top" 
     android:background="@drawable/obaz2" > 
    </RelativeLayout> 

</RelativeLayout> 
+0

하지만 두 가지 상대적인 레이아웃이 있습니다. 하나는 상단에 있고 다른 하나는 하단에 있습니다. 두 개의 상대 레이아웃 사이에 표시하고 싶습니다. 내 질문이 이해되지 않았다. – androidcodehunter

+0

기본 RelativeLayout을 사용합니다. 이 레이아웃에서는 두 개의 RelativeLayouts와 Button이 있습니다. 이 경우 버튼을 "세 번째"RelativeLayout 안에 둘 필요가 없습니다. – Zickoss

관련 문제