2013-05-29 79 views
0

我做了一个简单的布局,但我无法针对不同的屏幕尺寸优化它。我已经在5.1设备上看起来很好,但按钮在10.1上很小,在3.2屏幕上很大。我尝试过失败,并且对许多可能性感到沮丧,但似乎无法找到任何工作。任何想法将不胜感激,谢谢。这是我的基本布局的代码,在5.1英寸的屏幕上看起来很好。Android xml-如何优化设备布局

<RelativeLayout 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" 
tools:context=".Home" 
android:background="@drawable/bg"> 

<Button 
    android:id="@+id/playB" 
    android:layout_width="300dp" 
    android:layout_height="85dp" 
    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true 
    android:background="@drawable/menu_button"/> 

<Button 
    android:id="@+id/aboutB" 
    android:layout_alignLeft="@+id/playB" 
    android:layout_below="@+id/playB" 
    android:layout_marginTop="45dp"   
    android:layout_width="300dp" 
    android:layout_height="85dp" 
    android:layout_centerHorizontal="true" 
    android:background="@drawable/menu_button"/> 

<Button 
    android:id="@+id/settingsB" 
    android:layout_alignLeft="@+id/playB" 
    android:layout_below="@+id/aboutB" 
    android:layout_marginTop="45dp" 
    android:layout_width="300dp" 
    android:layout_height="85dp" 
    android:layout_centerHorizontal="true" 
    android:background="@drawable/menu_button"/> 

回答

0

使用dp是正确的方法。它不会是一个常数大小因为AOS会根据屏幕密度使用乘数来缩放DPS。 (顺便说一句==他们是完全一样的)所以DPS是密度独立的。然而,缩放通常是不够的。所以你需要为不同的屏幕创建单独的资源,我可能会说在da @ $$中支持多个屏幕是一个非常大的痛苦。好像只有一个好的,正确的方法是使用OpenGL ...
你可能会发现下面的链接有用:
How to use resource qualifier on layouts to distinguish smartphones like HTC Desire and Samsung Galaxy Nexus
image size (drawable-hdpi/ldpi/mdpi/xhdpi)
Avoid Multiple Drawable Sets (hdpi/mdpi/ldpi)
Widget Layout for 960x540 and 854x480
getDimension()/getDimensionPixelSize() - mutliplier issue
​​

+0

感谢所有那些我都帮助过的人。 Sorta new to android很高兴有像你这样的人来帮助我。我知道,在不同屏幕上获取应用程序大小可能很困难,但我也知道它会影响或破坏应用程序声誉。再次感谢!!! – user1576726

+0

不要忘了选择一个答案,当你能够做到这一点 – Stan

0

你用固定dp大小为你的按钮,所以他们会不断的大小。这可能会使它们在小屏幕上太大而在大屏幕上太小。我强烈建议您研究如何设计multiple screen sizes。至于你的问题,你可以1)使用你想要的按钮宽度与屏幕宽度的比率来设置按钮尺寸。这必须通过编程来检查设备尺寸; 2)为不同的屏幕创建不同的布局,如this

+0

嘿声音很大我可能会试图找到如何正确编程布局。任何关于我在哪里可以找到关于此主题的特定信息的链接或想法?感谢您的回复,非常感谢! – user1576726