2014-01-29 56 views
0

我已閱讀Android支持多屏幕教程。 當我試圖看到我的佈局如何適應不同的屏幕,出現了問題。在我的情況下,我只有一個圖像(970x174)的測試圖像被複制到所有可繪製文件夾中。 通過在不同的屏幕上看到我的佈局,在大多數情況下,佈局並不像我想的那樣。我貼我的佈局代碼(這很符合的Nexus 4屏幕)在不同的屏幕設備上修改的部件距離

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

<ImageView 
    android:id="@+id/TEMPORARY" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_marginBottom="128dp" 
    android:src="@drawable/button" /> 

<ImageView 
    android:id="@+id/image2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_marginBottom="64dp" 
    android:src="@drawable/button" /> 


<ImageView 
    android:id="@+id/image3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:src="@drawable/button" /> 
</RelativeLayout> 

也許我應該爲每個屏幕類型做了不同密度的形象?

回答

0

RelativeLayout沒有方向標籤,所以刪除它。

由於您在所有可繪製類型上放置了相同的圖像,圖像將具有固定的像素大小,隨着屏幕密度的增加,這將縮小屏幕上圖像的大小。但是您在版面上使用了dp作爲單位,因此隨着密度的增加,128dp的大小會增加,以使屏幕上的大小在不同設備上顯示爲相同。

因此,如果您希望在屏幕上擁有與屏幕密度相同大小的相同佈局,請刪除圖像的其他副本,並只留下一個可繪製文件夾,並且android會在不同的屏幕密度手機上處理縮放比例。

+0

如果我刪除一個或多個文件夾,當我不同的屏幕上測試我的佈局,一些屏幕看上去是空的,只有對應於繪製密度文件夾屏幕葉,是顯示 – giozh

+0

您是否嘗試過只用繪製/文件夾,也許你使用太限制限定符,更多信息在http://developer.android.com/guide/topics/resources/providing-resources.html#Compatibility –

+0

是的,我試過了,但是發生了我說的 – giozh

相關問題