2014-12-02 86 views
0

我正在嘗試開發一個Android應用程序,該應用程序應該看起來像我上個月所做的一個iOS。有一個背景圖像和三個按鈕的視圖。背景圖片有一個標題部分和一個頁腳部分,我需要三個按鈕來保持這兩部分。這是從iOS版本的截圖和我的android活動所需的輸出:在android中安裝三個按鈕和一個背景圖像

enter image description here

現在我現在有作爲活動佈局文件:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:background="@drawable/fondo_pantalla"> > 
<Button 
     android:id="@+id/button2" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_below="@+id/button1" 
     android:drawableLeft="@drawable/actividades_izq" 
     android:text="Actividades" /> 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:drawableLeft="@drawable/agenda_izq" 
     android:paddingTop="60dp" 
     android:text="Agenda" /> 

    <Button 
     android:id="@+id/button3" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_below="@+id/button2" 
     android:drawableLeft="@drawable/suscribete_izq" 
     android:text="Recibir Información de Juventud" /> 

</RelativeLayout> 

我想的是,在縱向模式下,所有設備上的佈局看起來都相同或非常相似。

現在它看起來非常不同,具體取決於屏幕大小。

enter image description here

任何幫助是值得歡迎的。

+0

@Ravi,你的意思是將背景圖像分爲三部分,一個標題部分,一箇中心部分和一個底部? – novato 2014-12-02 05:47:28

+0

@Ravi,謝謝。我會嘗試。 – novato 2014-12-02 05:49:14

回答

1

我認爲使用線性佈局與重量將解決您的問題。嘗試這個。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:weightSum="3" 
    android:background="@drawable/ic_action_search"> 


    <Button 
     android:id="@+id/button1" 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:drawableLeft="@drawable/ic_launcher" 
     android:text="Agenda" /> 
    <Button 
     android:id="@+id/button2" 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:drawableLeft="@drawable/ic_action_search" 
     android:text="Actividades" /> 

    <Button 
     android:id="@+id/button3" 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:drawableLeft="@drawable/fail" 
     android:text="Recibir Información de Juventud" /> 

</LinearLayout> 
+0

謝謝你,小更正,它是非常相似的所需的佈局.. – novato 2014-12-02 06:00:58

+0

@novato謝謝..快樂的編碼:) – 2014-12-02 06:03:48

1

試試這個,讓我知道結果。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:background="@drawable/fondo_pantalla"> > 
    <Button 
    android:id="@+id/button2" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_below="@+id/button1" 
    android:drawableLeft="@drawable/actividades_izq" 
    android:text="Actividades" 
    layout_weight="1" /> 

    <Button 
    android:id="@+id/button1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:drawableLeft="@drawable/agenda_izq" 
    android:paddingTop="60dp" 
    android:text="Agenda" 
    layout_weight="1"/> 

    <Button 
    android:id="@+id/button3" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:drawableLeft="@drawable/suscribete_izq" 
    android:text="Recibir Información de Juventud" 
    layout_weight="1"/> 

</LinearLayout> 
+0

謝謝,但從Remees的方法是一點點更好...謝謝你在任何情況下。 – novato 2014-12-02 05:59:57

1

可以先把BUTTON2到:

android:layout_centerInParent="true" 

和Button1以:

android:above="@+id\button2" 

這樣,至少它的中心,並且可以調整更好的屏幕尺寸。

+0

謝謝你,你的建議有助於改善。 – novato 2014-12-02 06:03:10

+0

很高興能幫到:) – 2014-12-02 06:04:31

1

我認爲你的問題是試圖提供所有屏幕大小和密度的佈局。這幾乎是不可能的。但你可以做的是在res文件夾中創建單獨的文件夾

layout-small 
layout-medium 
layout-large 

依此類推。請仔細閱讀本文,因爲在您的預覽中,您幾乎可以使用一種佈局來支持幾乎所有的屏幕大小和密度......

將您的自定義佈局放入單獨的佈局文件夾中,以便爲用戶提供他們想要的體驗。希望它有幫助;)

+0

謝謝,我會把你的建議考慮到下一個項目中。 – novato 2014-12-02 06:03:46

+0

@novato這就是爲什麼我把它發佈爲answere。如果您的項目變大,您將需要爲不同的屏幕尺寸和密度提供佈局。請享用 ! ;) – Mike 2014-12-02 06:43:40