I’m trying to create a button based menu using relative layout. I am trying to lay them out in a grid formation using the
android:below=""
android:above=""
android:toLeftOf=""
android:toRightOf=""
commands
I tried to add one more button below the three buttons I already had, but instead of the buttons resizing to fit the parent the fourth button instead drops below the screen edge. Is there a work around for this because I don’t want buttons to appear missing on smaller screens. Here is my layout
<RelativeLayout android:id="@+id/level1layout"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:layout_gravity="center_horizontal">
<Button android:id="@+id/OneLevel1Button"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:text="1"
android:textSize="25dp"
android:background="@drawable/warpbutton"
android:visibility="gone"/>
<Button android:id="@+id/OneLevel2Button"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:layout_below="@id/OneLevel1Button"
android:text="2"
android:textSize="25dp"
android:background="@drawable/warpbutton"
android:visibility="gone"/>
<Button android:id="@+id/OneLevel3Button"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:layout_below="@id/OneLevel2Button"
android:text="3"
android:textSize="25dp"
android:background="@drawable/warpbutton"
android:visibility="gone"/>
<Button android:id="@+id/OneLevel4Button"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:layout_below="@id/OneLevel3Button"
android:text="4"
android:textSize="25dp"
android:background="@drawable/warpbutton"
android:visibility="gone"/>
</RelativeLayout>
The visibilities are set to gone by default because they are hidden deeper in the menu system on start up.
Have you considered using a GridLayout? http://developer.android.com/reference/android/widget/GridLayout.html
At OP’s suggestion, a very helpful site creating a custom ButtonAdapterfor a
GridView.