2013-03-20 125 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

相關問題