如何拆分android屏幕水平2垂直3共6

时间:2015-03-20 13:17:42

标签: android android-layout android-studio android-imagebutton

好的我正在尝试将屏幕尺寸分成水平方向和垂直方向3每个部分

Windows 8.1 api 9上的Android工作室

这里是我想要的方式

enter image description here

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

这里是我尝试失败的代码

    <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>

4 个答案:

答案 0 :(得分:1)

这里的诀窍是使用一个LinearLayout作为父级,weightSum为4,orientation为垂直。然后使用3 LinearLayout个孩子,weightSum为2,orientation水平,weight为2,第一个为1,第二个和第三个为1。在这些LinearLayout内放置2 ImageButtonweight为1。

如果你想要一个例子告诉我,但我认为我很清楚。

P.S。所有layout_widthlayout_height必须为match_parent

答案 1 :(得分:1)

我认为你可以使用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 :(得分:1)

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

答案 3 :(得分:0)

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>
相关问题