2013-03-20 115 views
1

我创建了一个按钮布局设计,如图所示。我如何实现不同尺寸屏幕的设计模式?这种布局适合3.7英寸的屏幕,但不适用于其他屏幕。可能是scrollview是一个选项,但这并不能满足我。我该怎么做?任何帮助?需要针对不同类型设备的相同设计android

enter image description here

这是我的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=".MainActivity" > 

<Button 
    android:id="@+id/button1" 
    android:layout_width="match_parent" 
    android:layout_height="110dp" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="5dp" 
    android:text="Button" /> 

<Button 
    android:id="@+id/button2" 
    android:layout_width="match_parent" 
    android:layout_height="110dp" 
    android:layout_below="@+id/button1" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="5dp" 
    android:text="Button" /> 

<Button 
    android:id="@+id/button3" 
    android:layout_width="match_parent" 
    android:layout_height="110dp" 
    android:layout_below="@+id/button2" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="5dp" 
    android:text="Button" /> 

<Button 
    android:id="@+id/button4" 
    android:layout_width="match_parent" 
    android:layout_height="110dp" 
    android:layout_below="@+id/button3" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="5dp" 
    android:text="Button" 
    android:layout_marginBottom="5dp" /> 

回答

1

嗨,你可以重量而不是相对布局..如果你使用相对布局的概念,它将适合所有的屏幕。 尝试下面的XML并检查不同的屏幕。

<LinearLayout 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" 
     android:orientation="vertical" 
    android:weightSum="8" > 

    <Button 
android:id="@+id/button1" 
android:layout_width="match_parent" 
android:layout_height="0dp" 
    android:layout_weight="2" 
android:text="Button" /> 

    <Button 
android:id="@+id/button2" 
android:layout_width="match_parent" 
android:layout_height="0dp" 
android:layout_weight="2" 
android:text="Button" /> 

    <Button 
android:id="@+id/button3" 
android:layout_width="match_parent" 
android:layout_height="0dp" 
    android:layout_weight="2" 
android:text="Button" /> 

    <Button 
android:id="@+id/button4" 
android:layout_width="match_parent" 
android:layout_height="0dp" 
    android:layout_weight="2" 
android:text="Button" 
/> 
</LinearLayout> 

“线性”布局中的权重总和将占用整个屏幕大小。并且layout_weight会根据重量修复按钮。

+0

它甚至没有显示按钮:-( – 2013-03-20 05:47:49

+0

我编辑我的代码..现在试试这个 – user1835052 2013-03-20 05:49:22

+0

你试过我的代码... – user1835052 2013-03-20 05:56:39

2

看到这个链接,您可以了解不同的屏幕布局设计方案。 http://developer.android.com/guide/practices/screens_support.html

+0

请问你能举个例子吗? – 2013-03-20 05:58:51

+0

当然。如果你只使用这样的按钮,你可以这样做,但如果你在活动中拥有更多不同的UI,那么你需要为此创建不同的布局..我会给你举例... – 2013-03-20 06:04:46

+1

创建一个布局大的在res文件夹中的文件夹比创建main.xml,并给你想要在xml中设计UI,而不是在大屏幕显示设备中看到不同的设计。 – 2013-03-20 06:13:53

相关问题