2013-07-31 4 views
4

상대 레이아웃을 사용 중이며 첨부 된 이미지와 같이 아래쪽과 가운데에있는 TextView를 정렬하려고합니다. 나는 아래쪽을 사용하여 아래에 그것을 얻을 수 있지만 그들의 수평 중심을 정렬하는 방법을 알아낼 수 없습니다.상대 레이아웃 아래 항목을 다른 항목의 가운데에 맞 춥니 다

enter image description here

+0

상대 레이아웃에서이 두 가지를 넣고이 좋아 보인다 –

답변

6

가장 쉬운 방법은

<RelativeLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    > 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:src="@drawable/ic_launcher" /> 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/imageView1" 
     android:layout_centerHorizontal="true" 
     android:text="TextView" /> 

</RelativeLayout> 

편집

하나의 레이아웃에서이 작업을 수행하려면 당신의 텍스트 뷰에 android:drawableTop을 추가 할 상대 레이아웃에 이미지와 텍스트 뷰를 배치하는 것입니다

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="TextView" 
    android:drawableTop="@drawable/ic_launcher"/> 
+0

을 center_horizontal에 비해 레이아웃의 무게를 설정하지만 ANO 만들지 않고 그것을 할 기대했다 상대적인 레이아웃. – RunLoop

+0

동일한 레이아웃에서 작업하려면 DrawableTop with TextView를 사용하십시오. –

0

간단한 방법을 수행하는 :

  • 설정 "match_parent"에 layout_width 속성의
  • 의 폭이 그런 다음 "중력"을 "center_horizontal"를

속성을 설정이 방법 예 :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="match_parent" 
     android:gravity="center_horizontal" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:src="@drawable/ic_launcher" /> 

    <TextView 
     android:layout_below="@+id/imageView1" 
     android:id="@+id/textView1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="TextView" 
     android:gravity="center_horizontal" /> 

</RelativeLayout> 
관련 문제