2

我最近使用 Eclipse 开发了一个 android 游戏。我真的是这方面的新手,所以如果我要问的内容太简单,请原谅我。>.<

该应用程序在 Eclipse 中安装的 Android 模拟器中运行并且看起来完美。但是,当我们尝试将其安装在屏幕明显比模拟器大的三星 Galaxy 选项卡中时,布局变得一团糟。按钮的顺序不正确等。我确实有使用 XML 布局的屏幕,有些是带有精灵的简单画布。知道如何将模拟器中的原始布局保留到平板电脑吗?我试过使用RelativeLayout而不是,LinearLayout但它仍然不起作用。

任何帮助,将不胜感激。谢谢!

一个 XML 文件代码及其对应的模拟器屏幕如下所示。

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/MenuLayout" >

<Button android:id="@+id/btnNew"
    android:layout_width="140px"
    android:layout_height="65px"
    android:layout_marginTop="160px"
    android:background="@drawable/newgame"/>
<Button android:id="@+id/btnInst"
    android:layout_width="140px"
    android:layout_height="65px"
    android:background="@drawable/instructions" />
<Button android:id="@+id/btnCredits"
    android:layout_width="140px"
    android:layout_height="65px"
    android:background="@drawable/credits"/>
<Button android:id="@+id/btnExit"
    android:layout_width="140px"
    android:layout_height="65px"
    android:background="@drawable/exit"/> </LinearLayout>

上面xml的对应图像

4

4 回答 4

0

正如其他人所提到的,您应该使用“dp”而不是“px”。这些是与设备无关的像素,将缩放以匹配不同的屏幕分辨率。

您还应该遵循本指南,了解如何使用文件夹结构来支持不同的屏幕分辨率和尺寸。

干杯

于 2011-03-01T16:25:42.230 回答
0

根据您编辑的问题和评论,这是一种将布局更改为相对布局的方法:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     style="@style/MenuLayout"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent">

    <Button android:id="@+id/btnNew"
        android:layout_width="140dip"
        android:layout_height="65dip"
        android:layout_marginTop="160dip"
        android:background="@drawable/newgame" 
        android:layout_centerHorizontal="true" 
        android:layout_above="@+id/btnInst" />

    <Button android:id="@+id/btnInst"
        android:layout_width="140dip"
        android:layout_height="65dip"
        android:background="@drawable/instructions" 
        android:layout_centerHorizontal="true" 
        android:layout_above="@+id/btnCredits"/>

    <Button android:id="@+id/btnCredits"
        android:layout_width="140dip"
        android:layout_height="65dip"
        android:background="@drawable/credits"
        android:layout_centerHorizontal="true" 
        android:layout_above="@+id/btnExit"/>

    <Button android:id="@+id/btnExit"
        android:layout_width="140dip"
        android:layout_height="65dip"
        android:background="@drawable/exit"
        android:layout_centerHorizontal="true" 
        android:layout_alignParentBottom="true" 
        android:layout_marginBottom="25dip"/> 

</RelativeLayout>

不过,如果您想要一个完美的解决方案,您需要设计 3 种尺寸的按钮和背景图片,并将它们放在各自的文件夹中 drawable-hdpi、drawable-mdpi 和 drawable-ldpi(对于平板电脑,从 2.2 开始,您可以也有drawable-xhdpi!)。仔细阅读这篇文章,并在模拟器中测试尽可能多的屏幕布局(从ADT 10.0开始,直接从 xml 中的图形布局选项卡预览不同配置的布局非常容易)。

此外,在相对布局中android:layout_marginTop="160dip"android:layout_marginBottom="25dip"没有真正有用。我建议你为你的背景尝试一张9 补丁的图片,只有木板可以拉伸按钮(虽然我不确定它是否像那样工作)。或者,我会有一张单独的带有Main Menu的图片,我将它放在按钮上方,并且只在背景中保留树木和其他所有东西。

于 2011-03-02T08:43:16.873 回答
0

更好地为不同的屏幕尺寸提供不同的布局。我在开发游戏时也遇到了同样的问题。nw 完成了。你可能已经提供了布局,所以你只提供布局-大、小和 xlarge。反之亦然你的布局你必须提供可绘制的文件夹,如 hdpi、mdpi、ldpi、xdpi 文件夹,你必须保存不同大小的图像 58*58, 75*75,100*100 跟随然后你检查它你会得到它。

于 2015-03-04T10:05:05.170 回答
0

您需要使用 dpi 而不是像素。这是一个很好的资源。 http://developer.android.com/guide/practices/screens_support.html

于 2011-03-01T16:07:30.300 回答