android:layout_centerHorizontal="true" is not working in android
android, layout
Solution
In the layout, `RelativeLayout`'s width is set to `wrap-content`, its not taking the entire available width at all. It's contents are being centered but their parent `View` is shrinking to fit around them.
try `fill_parent` for root:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
Also, a `LinearLayout` with `orientation="vertical"` and `gravity="center_horizontal"` will do the same, more easily.
Problem
I am using this layout to make image and text in center.but its not working .i am simply using android:layout_centerHorizontal="true".why its not working i dont understand. can someone please help to solve this problem? ``` <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#ffffff"> <ImageView android:id="@+id/image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_marginTop="70dp" android:background="@drawable/image_tutorial1" /> <TextView android:textSize="14dp" android:id="@+id/title" android:layout_below="@+id/image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:text="@string/info4" android:textColor="#000000" android:textStyle="bold" /> </RelativeLayout> ```