Issue
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?
Solution
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" >
Answered By - Ahmad Alkhatib

0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.