Center View in RelativeLayout Android

RelativeLayout like parent, child Srollview is centered horizontal.
Second RelativeLayout in SrollView have gravity center, every child will centered horizontally and vertically.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:gravity="center_horizontal">
 
    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/scrollView2" >
 
        <RelativeLayout
            android:layout_width="320dp"
            android:layout_height="wrap_content"
            android:background="#e6f825"
            android:gravity="center">
 
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="New Button"
                android:id="@+id/button" />
        </RelativeLayout>
    </ScrollView>
 
</RelativeLayout>
This entry was posted in Android Examples Code and tagged . Bookmark the permalink.


Comments are closed.



1,886 views