[ACCEPTED]-How to bring button to center of the screen in Android-android-layout

Accepted answer
Score: 11

You could use a relative layout and set 3 the child to android:layout_centerInParent="true". LinearLayout are a little 2 tricky when it comes to centering check 1 out this article http://sandipchitale.blogspot.com/2010/05/linearlayout-gravity-and-layoutgravity.html.

Score: 5

Try using this layout!

<LinearLayout android:id="@+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal">
    <LinearLayout android:id="@+id/linearLayout2" android:layout_height="wrap_content" android:gravity="center" android:layout_width="match_parent">
        <Button android:text="Button" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
    </LinearLayout>
</LinearLayout>

0

Score: 4

It should be android:layout_gravity instead 1 of android:gravity.

More Related questions