2014-05-19 32 views
0

好吧! 我现在正在开发Android应用程序,但我想知道如何将所有布局放到多个设备屏幕上。Android多屏幕 - 将UI用于用户界面

*我做了多个屏幕文件夹。

RES /布局小/ main.xml中

RES /布局正常/ main.xml中

RES /布局大/ main.xml中

RES /布局XLARGE /主.xml

*下面是我的代码示例。

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 
    <LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" > 
    <Button 
    android:layout_width="120dp" 
    android:layout_height="70dp" 
    android:text="@sting/button1" > 
<Button 
    android:layout_width="120dp" 
    android:layout_height="70dp" 
    android:text="@sting/button2" > 
<Button 
    android:layout_width="120dp" 
    android:layout_height="70dp" 
    android:text="@sting/button3" > 
<Button 
    android:layout_width="120dp" 
    android:layout_height="70dp" 
    android:text="@sting/button3" > 
</LinearLayout> 
</LinearLayout> 

正如你所看到的,我对每个按钮都使用了120dp。 当我在虚拟设备机器中运行时,屏幕很合适。 (因为我在虚拟设备机器上使用了480dp宽度的屏幕。) 但是,当我在真实的手机设备(我的:三星Galaxy Note 1(韩国版),我父亲的:三星Galaxy S2(韩国版)和我妈妈的:三星Galaxy S(加拿大版)),尽管我创建了不同大小的屏幕文件夹,但我可以看到按钮的(宽度)距设备的屏幕布局太远。 谁能告诉我如何适应所有的设备屏幕? 在这种情况下,我仍然可以使用dp吗? (请给我一个例子!)

+0

你应该使用'wrap_content'或'match_parent' – tyczj

+0

@tyczj谢谢您的答复。我确实使用了wrap_content,它看起来很糟糕。我不喜欢普通的按钮风格。 – user3653228

回答

0

你需要阅读使用LinearLayoutRelativeLayout(和其他布局)。你根本没有使用他们的布局参数。您不需要指定任何特定的大小(如120dp)以支持您的情况的多种屏幕大小。

http://developer.android.com/guide/topics/ui/declaring-layout.html

这里是你应该做的:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal" 
       android:weightSum="4"> 

    <Button 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:text="@sting/button1" 
     android:layout_weight="1" /> 

    <Button 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:text="@sting/button2" 
     android:layout_weight="1" /> 

    <Button 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:text="@sting/button3" 
     android:layout_weight="1" /> 

    <Button 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:text="@sting/button4" 
     android:layout_weight="1" /> 
</LinearLayout> 
+0

感谢您的评论。那么如果高度相同,我应该怎么做呢?高度不适用于“android:layout_weight”,所以.. – user3653228

+0

你想要的高度是多少? – ashishduh