2012-07-06 100 views
0

我想創建一個在所有設備上顯示的佈局,就像它在我的手機上一樣。我試圖讓它適用於平板電腦,但它看起來很糟糕。 這是它應該是什麼樣子: enter image description here相對佈局縮放?

但在這裏是如何出現在這片模擬器: enter image description here

我能做些什麼,使之出現在所有屏幕尺寸喜歡它是我的手機上?我目前正在使用RelativeLayout。 這裏是我的代碼:

<?xml version="1.0" encoding="UTF-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/RelativeLayout02" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" > 

<ImageView 
    android:id="@+id/terranlogo1" 
    android:layout_width="100dp" 
    android:layout_height="100dp" 
    android:layout_centerHorizontal="true" 
    android:src="@drawable/terranlogo" /> 

<ImageView 
    android:id="@+id/protosslogo1" 
    android:layout_width="100dp" 
    android:layout_height="100dp" 
    android:layout_alignParentRight="true" 
    android:src="@drawable/protosslogo" /> 

<ImageView 
    android:id="@+id/zerglogo1" 
    android:layout_width="100dp" 
    android:layout_height="100dp" 
    android:layout_alignParentLeft="true" 
    android:src="@drawable/zerglogo" /> 

<CheckBox 
    android:id="@+id/ck_t1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/terranlogo1" 
    android:layout_centerHorizontal="true" /> 

<CheckBox 
    android:id="@+id/ck_p1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@id/protosslogo1" 
    android:layout_below="@id/protosslogo1" 
    android:layout_marginLeft="25dp" /> 

<CheckBox 
    android:id="@+id/ck_z1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignBaseline="@id/zerglogo1" 
    android:layout_below="@id/zerglogo1" 
    android:layout_marginLeft="25dp" /> 

<ImageView 
    android:id="@+id/terranlogo2" 
    android:layout_width="100dp" 
    android:layout_height="100dp" 
    android:layout_below="@id/ck_t1" 
    android:layout_centerHorizontal="true" 
    android:src="@drawable/terranlogo" /> 

<ImageView 
    android:id="@+id/protosslogo2" 
    android:layout_width="100dp" 
    android:layout_height="100dp" 
    android:layout_alignParentRight="true" 
    android:layout_below="@id/ck_p1" 
    android:src="@drawable/protosslogo" /> 

<ImageView 
    android:id="@+id/zerglogo2" 
    android:layout_width="100dp" 
    android:layout_height="100dp" 
    android:layout_alignParentLeft="true" 
    android:layout_below="@id/ck_z1" 
    android:src="@drawable/zerglogo" /> 

<CheckBox 
    android:id="@+id/ck_t2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/terranlogo2" 
    android:layout_centerHorizontal="true" /> 

<CheckBox 
    android:id="@+id/ck_p2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@id/protosslogo1" 
    android:layout_below="@id/protosslogo2" 
    android:layout_marginLeft="25dp" /> 

<CheckBox 
    android:id="@+id/ck_z2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignBaseline="@id/zerglogo1" 
    android:layout_below="@id/zerglogo2" 
    android:layout_marginLeft="25dp" /> 

<TextView 
    android:id="@+id/textView4" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/ck_t2" 
    android:layout_marginRight="18dp" 
    android:layout_marginTop="17dp" 
    android:gravity="center_vertical|center_horizontal" 
    android:text="Choose your opponets race(s) and your race(s)" 
    android:textSize="30dp" /> 

<TextView 
    android:id="@+id/textView3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentRight="true" 
    android:text="Game Length" 
    android:textSize="15dp" /> 

<Spinner 
    android:id="@+id/s_answertime" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/textView1" 
    android:layout_alignParentLeft="true" 
    android:layout_below="@id/textView4" /> 

<TextView 
    android:id="@+id/textView2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@+id/terranlogo2" 
    android:layout_alignParentBottom="true" 
    android:gravity="center_horizontal" 
    android:text="Mistakes Allowed" 
    android:textSize="15dp" /> 

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:text="Answer Time" 
    android:textSize="15dp" /> 





<Spinner 
    android:id="@+id/s_mistakenumber" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignBottom="@+id/s_answertime" 
    android:layout_alignTop="@+id/s_answertime" 
    android:layout_toLeftOf="@+id/s_gametime" 
    android:layout_toRightOf="@+id/s_answertime" /> 



<Spinner 
    android:id="@+id/s_gametime" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/textView3" 
    android:layout_alignLeft="@+id/protosslogo2" 
    android:layout_alignTop="@+id/s_mistakenumber" /> 

</RelativeLayout> 

所有幫助表示讚賞,Lijap。

+0

您應該使用真實設備來測試您的應用程序,但實際上這很簡單,您應該將其與LinearLayout分開並使用layout_weight – IamStalker 2012-07-06 18:12:00

+0

我無法使用LinearLayout以我想要的方式查看它。我一遍又一遍地嘗試,我想我沒有做對,但我無法弄清楚。 – Lijap 2012-07-06 18:26:28

回答

1

因爲您設置了layout_above和layout_below,因此它們會拉伸以適應這兩個條件。刪除其中一個(可能是layout_above)併爲它們設置一個合理的固定高度(75dp?)。

此外,您的左/右大多數圖標/複選框可能會更好,邊緣良好,margin_left/right = 50dp,以防止它們一直延伸到屏幕邊緣。