1

我正在为 android 开发我的游戏菜单,并且我坚持将我的布局应用于所有设备的屏幕尺寸。

我必须以 dp 或 weight 调整布局的大小吗?

我知道在 layout-large、layout-small... 和 drawable-hdpi、drawable-ldpi 中做了很多布局...但我仍然卡住了。

你会怎么做?

你可以找到我想要的骨架:http: //imageshack.us/photo/my-images/14/menuskeleton.jpg/

谢谢 !

4

2 回答 2

1

我建议您使用重量来保持与其他格式平板电脑的互操作性。

我的解决方案:

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

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:orientation="horizontal"
    tools:ignore="DisableBaselineAlignment" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="horizontal"
        tools:ignore="NestedWeights" >

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

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:layout_weight="1"
                android:background="#DDDDDD"
                android:gravity="center"
                android:orientation="vertical" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Shop"
                    tools:ignore="HardcodedText" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:layout_weight="1"
                android:background="#DDDDDD"
                android:gravity="center"
                android:orientation="vertical" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Ladder"
                    tools:ignore="HardcodedText" />

            </LinearLayout>
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="10dp"
            android:layout_weight="1"
            android:background="#DDDDDD"
            android:gravity="center"
            android:orientation="vertical" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Profil"
                tools:ignore="HardcodedText" />

        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="20dp"
        android:layout_weight="1"
        android:background="#DDDDDD"
        android:gravity="center"
        android:orientation="vertical" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Recap_All"
            tools:ignore="HardcodedText" />

    </LinearLayout>
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:orientation="horizontal"
    tools:ignore="DisableBaselineAlignment" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="20dp"
        android:layout_weight="1"
        android:background="#DDDDDD"
        android:gravity="center"
        android:orientation="vertical"
        tools:ignore="NestedWeights" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView"
            tools:ignore="HardcodedText" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="20dp"
        android:layout_weight="1"
        android:background="#DDDDDD"
        android:gravity="center"
        android:orientation="vertical" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="PLAY"
            tools:ignore="HardcodedText" />

    </LinearLayout>
</LinearLayout>

结果是图片:

在此处输入图像描述

我希望你有帮助!

于 2013-05-19T09:31:01.143 回答
0

On this page of google developers, has a description of how to develop for different screen sizes.

And this page is the answer to your question about the size of your layout, it is between dp or weight.

See this also.

于 2013-05-19T09:42:32.783 回答