Q:

WebView in RelativeLayout doesn't center

I have a layout:
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    <WebView
        android:layout_width="400dp"
        android:layout_height="match_parent"
        android:layout_centerHorizontal="true" />
</RelativeLayout>

When looking the the Android Studio layout designer, the WebView is centred as expected. When pushed onto a device or run in the emulator, the WebView is left justified, ignoring the centerHorizontal tag. Below is a screenshot with show view bounds enabled.

How can I get the WebView to centre?

A:

Make sure the parent was set as match_parent like this .
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

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

    <WebView
        android:layout_width="400dp"
        android:layout_height="match_parent"
        android:layout_centerHorizontal="true" />
       </RelativeLayout>

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

