Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Relative Layout align an item below and to the middle of another item

Tags:

android

I am using a relative layout and want to align a TextView below and in the middle of a button as shown in the attached image. I have can get it to the bottom using BELOW, but cant figure out how to align their horizontal centers.

enter image description here

like image 325
RunLoop Avatar asked Jul 31 '13 11:07

RunLoop


1 Answers

Easiest way is to put image and textview into a relative layout

 <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>

Edit

To do this in single Layout add android:drawableTop to your TextView

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView" 
    android:drawableTop="@drawable/ic_launcher"/>
like image 87
Arun C Avatar answered Oct 06 '22 23:10

Arun C