如何拆分android屏幕横2竖3共6

How to split android screen horizontal 2 vertical 3 total 6

好的,我正在尝试将屏幕大小水平平均分割,垂直分割为每个部分 3

Android 工作室 windows 8.1 api 9

这里是我想要的图片

每张图片都是这些尺寸,我希望它们根据较低的分辨率按比例缩放

这是我尝试过但失败的代码

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
 tools:context=".Pokemon"
    android:background="@color/background_floating_material_dark"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:baselineAligned="false"
  >



    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1">

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/register_monstermmorpg_1"
            android:background="@null"
            android:src="@drawable/bg_monstermmorpg_button_land"
            android:adjustViewBounds="true"
            android:scaleType="centerCrop"


            />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/register_monstermmorpg_2"
            android:background="@null"
            android:src="@drawable/Register_monstermmorpg_land"
            android:adjustViewBounds="true"
            android:scaleType="centerCrop"

            />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/login_monstermmorpg"
            android:background="@null"
            android:src="@drawable/Login_monstermmorpg_land"
            android:adjustViewBounds="true"
            android:scaleType="centerCrop"

            />

    </RelativeLayout>
    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1">
        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/register_pokemonets_1"
            android:background="@null"
            android:src="@drawable/bg_pokemonpets_button_land"
            android:adjustViewBounds="true"
            android:scaleType="centerCrop"

            />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/register_pokemonets_2"
            android:background="@null"
            android:src="@drawable/Register_pokemonpets_land"
            android:adjustViewBounds="true"
            android:scaleType="centerCrop"

            />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/login_pokemonpets"
            android:background="@null"
            android:src="@drawable/Login_pokemonpets_land"
            android:adjustViewBounds="true"
            android:scaleType="centerCrop"

            />
    </RelativeLayout>
</LinearLayout>

这里的技巧是使用一个 LinearLayout 作为 parent,weightSum 为 4,orientation 垂直。然后使用 3 LinearLayout 个孩子,其中 weightSum 为 2,orientation 水平,第一个 weight 为 2,第二个和第三个为 1。在这些 LinearLayout 中放 2 ImageButtonweight of 1.

如果你想要一个例子告诉我,但我想我已经很清楚了。

P.s。所有 layout_widthlayout_height 必须是 match_parent

我认为您可以简单地使用 GridView

布局方面

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
 tools:context=".Pokemon"
    android:background="@color/background_floating_material_dark"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:baselineAligned="false"
  >

<LinearLayout


    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:weightsum="2"
  >

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
android:orientation:vertical
android:weightsum="3"
        android:layout_weight="1">

        <ImageButton
            android:layout_width="match_parent"
            android:layout_height="0dp"
 android:layout_weight="1"
            android:id="@+id/register_monstermmorpg_1"
            android:background="@null"
            android:src="@drawable/bg_monstermmorpg_button_land"
            android:adjustViewBounds="true"
            android:scaleType="centerCrop"


            />

        <ImageButton
            android:layout_width="match_parent"
            android:layout_height="0dp"
 android:layout_weight="1"
            android:id="@+id/register_monstermmorpg_2"
            android:background="@null"
            android:src="@drawable/Register_monstermmorpg_land"
            android:adjustViewBounds="true"
            android:scaleType="centerCrop"

            />

        <ImageButton
            android:layout_width="match_parent"
            android:layout_height="0dp"
 android:layout_weight="1"
            android:id="@+id/login_monstermmorpg"
            android:background="@null"
            android:src="@drawable/Login_monstermmorpg_land"
            android:adjustViewBounds="true"
            android:scaleType="centerCrop"

            />

    </LinearLayout>
    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
android:orientation:vertical
android:weightsum="3"
        android:layout_weight="1">
        <ImageButton
           android:layout_width="match_parent"
            android:layout_height="0dp"
 android:layout_weight="1"
            android:id="@+id/register_pokemonets_1"
            android:background="@null"
            android:src="@drawable/bg_pokemonpets_button_land"
            android:adjustViewBounds="true"
            android:scaleType="centerCrop"

            />

        <ImageButton
            android:layout_width="match_parent"
            android:layout_height="0dp"
 android:layout_weight="1"
            android:id="@+id/register_pokemonets_2"
            android:background="@null"
            android:src="@drawable/Register_pokemonpets_land"
            android:adjustViewBounds="true"
            android:scaleType="centerCrop"

            />

        <ImageButton
            android:layout_width="match_parent"
            android:layout_height="0dp"
 android:layout_weight="1"
            android:id="@+id/login_pokemonpets"
            android:background="@null"
            android:src="@drawable/Login_pokemonpets_land"
            android:adjustViewBounds="true"
            android:scaleType="centerCrop"

            />
    </RelativeLayout>


<RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1">

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/register_monstermmorpg_1"
            android:background="@null"
            android:src="@drawable/bg_monstermmorpg_button_land"
            android:adjustViewBounds="true"
            android:scaleType="centerCrop"


            />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/register_monstermmorpg_2"
            android:background="@null"
            android:src="@drawable/Register_monstermmorpg_land"
            android:adjustViewBounds="true"
            android:scaleType="centerCrop"

            />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/login_monstermmorpg"
            android:background="@null"
            android:src="@drawable/Login_monstermmorpg_land"
            android:adjustViewBounds="true"
            android:scaleType="centerCrop"

            />

    </RelativeLayout>
    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1">
        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/register_pokemonets_1"
            android:background="@null"
            android:src="@drawable/bg_pokemonpets_button_land"
            android:adjustViewBounds="true"
            android:scaleType="centerCrop"

            />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/register_pokemonets_2"
            android:background="@null"
            android:src="@drawable/Register_pokemonpets_land"
            android:adjustViewBounds="true"
            android:scaleType="centerCrop"

            />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/login_pokemonpets"
            android:background="@null"
            android:src="@drawable/Login_pokemonpets_land"
            android:adjustViewBounds="true"
            android:scaleType="centerCrop"

            />
    </LinearLayout>
</LinearLayout>

首先你需要一个权重和为2的水平LinearLayout。 在其中,应该是 2 个垂直的 LinearLayouts,权重和为 4,每个权重为 1。 在这两个布局中,添加 3 个图像按钮。顶部权重为2,其他权重为1

Using layout weight can be a good solution.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1" >

            <Button
                android:id="@+id/button1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="Button1" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1" >

            <Button
                android:id="@+id/Button01"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="Button2" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1" >

            <Button
                android:id="@+id/Button02"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="Button3" />

        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1" >

            <Button
                android:id="@+id/Button05"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="Button3" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1" >

            <Button
                android:id="@+id/Button04"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="Button2" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1" >

            <Button
                android:id="@+id/Button03"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="Button1" />
        </LinearLayout>
    </LinearLayout>

</LinearLayout>

</LinearLayout>