[ACCEPTED]-How to bring button to center of the screen in Android-android-layout
Accepted answer
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.
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
It should be android:layout_gravity instead 1 of android:gravity.
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.