I’m trying to have a menu of 2 buttons vertically. I set the layout to RelativeLayout . The first button is centered by
android:layout_centerVertical=”true”
android:layout_centerHorizontal=”true”
which works.
when I tried to add the second button to be under the first button by
android:layout_toBottomOf=”@+id/menuat”
it gives me a error.
How would I center more then one button on the screen?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/backFeetGallery"
android:background="@drawable/background"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/menua"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:text="But A"
/>
<Button
android:id="@+id/menub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_toBottomOf="@+id/menuat"
android:text="But B"
/>
</RelativeLayout>
layout_toBottomOfisn’t a valid parameter. Uselayout_belowinstead.Here’s the amended code:
By replacing this code you would get menub to be below menua
The full set of relative positions are: