I got a Main Menu with four buttons (attached), I would like to align all buttons to the center (including the "Main Menu" textView), and I would like to make sure that each buttons are all evenly spaced out.
I added android:gravity="center"> but its not aligning to center. Also to evenly space out the buttons I tried to add android:layout_weight="1" as one of the Button attributes but my button disappears from the screen.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
<TextView android:text="Main Menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button android:text="Button"
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="0dp"/>
<Button android:text="Button"
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="0dp"/>
<Button android:text="Button"
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="0dp"/>
<Button android:text="Button"
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="0dp"/>
</LinearLayout>
Change your LinearLayout width and height from wrap_content to match_parent..like this..