Align TextView under ImageButton in relative layout

I am having difficulty aligning the center of the text under the image button, although I tried the android: gravity = "center" property, the first two text views are centered on the corresponding image buttons, and the third is not very good, 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> 
+4
source share
1 answer

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" /> 
+8
source

All Articles