2011-02-11 2 views
1

내 레이아웃에서 두 개의 버튼이 같은 줄에 있으며, 하나는 왼쪽 정렬되고 다른 하나는 오른쪽 정렬됩니다. 레이블 역할을하는 단추 위에 TextViews도 있지만 왼쪽과 오른쪽도 각각 정렬되어 있습니다. 나는 그 (것)들을 대신에 단추의 위 그리고 동일한 선에 중심에두고 싶으면, 그러나 나는 명시 적으로 조정을하지 않으면 이것을하는 방법을 알아낼 수 없다, 그 때 몇몇 전화에 끊을 것이다. 다양한 가중치와 레이아웃 옵션을 설정해 보았지만 어떻게하면 좋을까요? RelativeLayout에서이 작업을 수행 할 수있는 방법이 있습니까? 아니면 불가능할 수도 있습니다.RelativeLayout 두 개의 TextViews가 위의 가운데에 배치 됨

미리 감사드립니다.

답변

2

난 그냥 여기 RelativeLayers의 두 가지 수준으로했는데, 한 출력이다

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/relativeLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <RelativeLayout 
     android:id="@+id/relativeLayout2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" > 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignBaseline="@+id/textView2" 
      android:layout_centerHorizontal="true" 
      android:text="Label longer than the button" > 
     </TextView> 

     <Button 
      android:id="@+id/button1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_below="@+id/textView1" 
      android:text="Button short" > 
     </Button> 
    </RelativeLayout> 

    <RelativeLayout 
     android:id="@+id/relativeLayout3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" > 

     <Button 
      android:id="@+id/button2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_below="@+id/textView2" 
      android:text="Button some longer" > 
     </Button> 

     <TextView 
      android:id="@+id/textView2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:text="Test" > 
     </TextView> 
    </RelativeLayout> 
</RelativeLayout> 
+0

굉장합니다, 고마워요! 이것은 트릭을해야합니다. – Matt

+0

멋진 접근 방식, +1. – Mudassir

2

2 열 2 행의 테이블 레이 아웃을 만듭니다.

첫 번째와 마지막 열은 수축 가능하고 가운데 열은 늘릴 수 있도록하십시오.

|----|-------------------|-----| 
| 1 |     | 2 | 
|----|-------------------|-----| 
| 3 |     | 4 | 
|----|-------------------|-----| 

3에 당신의 1과 2에서 라벨 및 버튼을 넣고 4 는 모든 열 내용을 중심으로. enter image description here

및 코드 :

+0

감사합니다,이게 내가 원래 생각 것입니다,하지만 난이었다 RelativeLayouts를 사용하고 TableLayouts을 피하려고합니다. – Matt

관련 문제