Here what im done to make the the button at the center
CodePudding user response:
You should be using android:layout_gravity
instead of android:gravity
, as the latter is used to set the gravity of its subviews.
layout_gravity
should however align the button on the center as this one is relative to its parent.
CodePudding user response:
you can use one of this layouts
RelativeLayout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"/>
</RelativeLayout>
or LinearLayout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
but i recommend you learn android ui design from here