2011-03-01 127 views
2

我最近开发了一个使用Eclipse的android游戏。我真的是一个新手,所以原谅我,如果我会问的太简单了。 >。 <ANDROID布局从模拟器变成了平板电脑

应用程序在安装在Eclipse中的Android模拟器中运行并看起来很完美。但是,当我们试图将它安装在明显比模拟器更大屏幕的Samsung 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> 

corresponding image for xml above

+3

它肯定会帮助你发布一些关于这个布局问题的图片。和布局文件。 – 2011-03-01 15:48:52

+0

当你想在任何尺寸的屏幕上显示正确的东西时,应该使用RelativeLayout。设置尺寸时,您还应该确保使用倾角而不是像素。 – 2011-03-01 16:00:19

+0

建议:你也可以设置一个三星Galaxy Tab模拟器,在这里看到详细信息:[http://innovator.samsungmobile.com/galaxyTab.do]我相信你的问题出现,因为你没有正确编程为不同的屏幕尺寸和密度(如使用px),而不是模拟器/设备本身。 – Adinia 2011-03-01 16:02:50

回答

0

正如其他人所说,你应该使用“DP”,而不是“像素”。这些是与设备无关的像素,可以缩放以匹配不同的屏幕分辨率。

您还应该按照此guide关于如何使用文件夹结构来支持不同的屏幕分辨率和尺寸。

干杯

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!)。仔细阅读article并在模拟器中测试您的布局,以获得尽可能多的屏幕(从ADT 10.0开始,可以直接从xml中的图形布局选项卡预览不同配置的布局)。

而且,android:layout_marginTop="160dip"android:layout_marginBottom="25dip"在相对布局中并不真正有用。我建议你尝试9-patch picture为你的背景,只有木板拉伸按钮(虽然我不知道它的工作是这样的)。或者,我将与主菜单分开显示一个单独的图片,我将它放在按钮上方,并仅保留背景树木和其他所有内容。

0

itz最好为不同的屏幕尺寸提供不同的布局。在开发游戏时,我也有同样的问题。 你可能提供了布局,所以你只需提供 layout-large,small和xlarge.and你的布局的反面你必须提供可绘制的文件夹如hdpi,mdpi,ldpi,xdpi文件夹和你必须保存不同大小的图像58 * 58,75 * 75,100 * 100以下ü检查你会得到它。