Using a relative layout for a menu on a game for android, however, launching different size emulators and the layout doesn't scale at all well even though i'm using dip. On a medium screen it works fine, however a small screen cuts half the bottom buttons off and the large screen scrunches all the buttons further up the screen, any ideas?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/menubackground"
>
<Button
android:text="High Scores"
android:layout_height="wrap_content"
android:layout_width="200dp"
android:id="@+id/HighScore"
android:layout_belo开发者_如何学JAVAw="@+id/NewGame"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:textStyle="bold"
></Button>
<Button
android:text="Instructions"
android:layout_height="wrap_content"
android:layout_width="200dp"
android:id="@+id/Instructions"
android:layout_below="@+id/HighScore"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:textStyle="bold"
></Button>
<Button
android:text="Exit"
android:layout_height="wrap_content"
android:layout_width="200dp"
android:id="@+id/Exit"
android:layout_below="@+id/Instructions"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:textStyle="bold"
>
</Button>
<Button android:layout_height="wrap_content"
android:textStyle="bold"
android:id="@+id/NewGame"
android:text="New Game"
android:layout_width="200dp"
android:layout_alignParentTop="true"
android:layout_alignLeft="@+id/HighScore"
android:layout_marginTop="191dp"></Button>
</RelativeLayout>
Perhaps a RelativeLayout
is not the best choice here. What I would do is use a LinearLayout
in a vertical direction. Using weight
you can make it so that allow the elements are evenly spaced out no matter the screen size. Perhaps, try something like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<Button android:id="@+id/new_game"
android:layout_width="200dp"
android:layout_height="0dp"
android:layout_weight="1"
android:text="feasdf"
/>
<Button android:id="@+id/instructions"
android:layout_width="200dp"
android:layout_height="0dp"
android:layout_weight="1"
android:text="feasdf"
/>
<Button android:id="@+id/exit_game"
android:layout_width="200dp"
android:layout_height="0dp"
android:layout_weight="1"
android:text="feasdf"
/>
Let me know if you've got any other questions!
Put the RelativeLayout
into a ScrollView
documentation. This will display the part that is being cut off on smaller screen sizes. It won't affect larger screen sizes where all the content can be viewed on the screen.
精彩评论