我正在开发Android游戏应用。在PlayGame布局上我使用嵌套的Linerlayout显示按钮(垂直)然后在里面我使用Relativelayout来显示侧面托盘,它们也是显示在屏幕右侧和左侧的按钮(垂直对齐)。问题是,所有按钮都不适合在屏幕尺寸上它们安装在一起。你能建议我如何解决这个问题吗?请在这里找到我的代码。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button android:id="@+id/btn6Player2"
android:layout_width="80dp"
android:layout_height="80dp"
android:text="@string/btnSeed6"
android:textAlignment="center"
android:background="@drawable/bluebowl"
/>
<Button android:id="@+id/btn5Player2"
android:layout_width="80dp"
android:layout_height="80dp"
android:text="@string/btnSeed5"
android:textAlignment="center"
android:background="@drawable/bluebowl"
/>
<Button android:id="@+id/btn4Player2"
android:layout_width="80dp"
android:layout_height="80dp"
android:text="@string/btnSeed4"
android:textAlignment="center"
android:background="@drawable/bluebowl"
/>
<Button android:id="@+id/btn3Player2"
android:layout_width="80dp"
android:layout_height="80dp"
android:text="@string/btnSeed3"
android:textAlignment="center"
android:background="@drawable/bluebowl"
/>
<Button android:id="@+id/btn2Player2"
android:layout_width="80dp"
android:layout_height="80dp"
android:text="@string/btnSeed2"
android:textAlignment="center"
android:background="@drawable/bluebowl"
/>
<Button android:id="@+id/btn1Player2"
android:layout_width="80dp"
android:layout_height="80dp"
android:text="@string/btnSeed1"
android:textAlignment="center"
android:background="@drawable/bluebowl"
/>
</LinearLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button android:id="@+id/trayPlayer1"
android:layout_width="80dp"
android:layout_height="80dp"
android:text="@string/btnTray2"
android:textAlignment="center"
android:layout_alignParentRight="true"
android:background="@drawable/pinktray"
/>
<Button android:id="@+id/trayPlayer2"
android:layout_width="80dp"
android:layout_height="80dp"
android:text="@string/btnTray1"
android:textAlignment="center"
android:layout_alignParentLeft="true"
android:background="@drawable/bluetray"
/>
</RelativeLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button android:id="@+id/btn1Player1"
android:layout_width="80dp"
android:layout_height="80dp"
android:text="@string/btnSeed1"
android:textAlignment="center"
android:background="@drawable/pinkbowl"
/>
<Button android:id="@+id/btn2Player1"
android:layout_width="80dp"
android:layout_height="80dp"
android:text="@string/btnSeed2"
android:textAlignment="center"
android:background="@drawable/pinkbowl"
/>
<Button android:id="@+id/btn3Player1"
android:layout_width="80dp"
android:layout_height="80dp"
android:text="@string/btnSeed3"
android:textAlignment="center"
android:background="@drawable/pinkbowl"
/>
<Button android:id="@+id/btn4Player1"
android:layout_width="80dp"
android:layout_height="80dp"
android:text="@string/btnSeed4"
android:textAlignment="center"
android:background="@drawable/pinkbowl"
/>
<Button android:id="@+id/btn5Player1"
android:layout_width="80dp"
android:layout_height="80dp"
android:text="@string/btnSeed5"
android:textAlignment="center"
android:background="@drawable/pinkbowl"
/>
<Button android:id="@+id/btn6Player1"
android:layout_width="80dp"
android:layout_height="80dp"
android:text="@string/btnSeed6"
android:textAlignment="center"
android:background="@drawable/pinkbowl"
/>
</LinearLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button android:id="@+id/btnBackPlayGame"
android:layout_width="80dp"
android:layout_height="80dp"
android:text="@string/btnBack"
android:textAlignment="center"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
</LinearLayout>
答案 0 :(得分:1)
我按照Opiatefuchs评论并为每个顶行和底行按钮分配了重量,这对我有用。这是示例代码
<Button android:id="@+id/btn5Player2"
android:layout_width="80dp"
android:layout_height="80dp"
android:text="@string/btnSeed5"
android:textAlignment="center"
android:background="@drawable/bluebowl"
android:layout_weight="1"
/>