Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Align TextView below an ImageButton in a Relative Layout

I'm having difficulties in aligning center a text view below an image button though I tried the property android:gravity="center", the first two text views are aligned in center of the corresponding image buttons, but the third one didn't fit well here is my xml code:

<ImageView
    android:id="@+id/view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:scaleType="fitXY"
    android:background="@null"
    android:src="@drawable/imageview" />


<ImageButton
    android:id="@+id/recBook"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textViewBook"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="30dp"
    android:layout_marginTop="107dp"
    android:background="@null"
    android:scaleType="fitXY"
    android:src="@drawable/recipebook" />

<TextView
    android:id="@+id/textViewBook"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/recBook"
    android:layout_marginLeft="33dp"
    android:text="@string/BookTV"
    android:textAppearance="?android:attr/textAppearanceSmall" />

<ImageButton
    android:id="@+id/search"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/textViewBook"
    android:layout_marginLeft="60dp"
    android:layout_toRightOf="@+id/textViewBook"
    android:background="@null"
    android:scaleType="fitXY"
    android:src="@drawable/search" />

<TextView
    android:id="@+id/textViewSearch"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/textViewBook"
    android:layout_alignBottom="@+id/textViewBook"
    android:layout_marginLeft="37dp"
    android:layout_toRightOf="@+id/textViewBook"
    android:text="@string/Search"
    android:textAppearance="?android:attr/textAppearanceSmall" />

<ImageButton
    android:id="@+id/favorite"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/recBook"
    android:layout_centerVertical="true"
    android:background="@null"
    android:scaleType="fitXY"
    android:src="@drawable/favorites" />

<TextView
    android:id="@+id/textViewFav"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_="@+id/favorite"
    android:layout_alignLeft="@+id/textViewBook"
    android:layout_below="@+id/favorite"
    android:text="@string/FavTV"
    android:textAppearance="?android:attr/textAppearanceSmall" />

</RelativeLayout>
like image 671
Sarah Zaky Avatar asked Jan 15 '23 06:01

Sarah Zaky


1 Answers

Use RelativeLayout and use this:

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/imageButton"
    android:layout_centerInParent="true"
    android:text="text" />
like image 52
A B Avatar answered Jan 22 '23 16:01

A B