2011-12-08 63 views
2

我很努力地完成我的Android應用程序,但我在使用用戶界面時遇到了一些問題。我的問題是非常基本的,在Eclipse中使用AVD管理器(HVGA,密度爲160 dpi)時,我開發了使用默認AVD的UI,當我執行應用程序時,按照我的設計看到它,但是如果我更改目標設備(即WVGA或QVGA)佈局中的所有組件位於與原始位置不同的位置。據我在支持多屏幕的建議中看到,我不應該使用AbsoluteLayouts,實際上我使用RelativeLayouts,我沒有使用尺寸(或位置)的「px」,只是「wrap_content」或「fill_parent 「,如果我需要一個特定的位置,我使用」dp「(也用」sp「進行測試),我也縮放了ldpi(0.75x)的圖像,並且仍然存在問題(不是特定的屏幕,洞應用程序).​​..所以,我的問題是,是否有任何其他的UI提示,我失蹤?
我把一個示例代碼和我用HVGA AVD(更大圖像)和QVGA AVD進行測試時觀察到的結果。如您所見,黃色/綠色方塊的位置不同,以及最後一排圖像的尺寸也不同。
PS:我也使用TabLayout,所以背景通過代碼加載(tabHost.setBackgroundDrawable(getResources()。getDrawable(R.drawable.background1)))
任何幫助將不勝感激。無法支持多個屏幕分辨率

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:id="@+id/row1" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="140dp" 
    > 
    <ImageView 
     android:id="@+id/btn1" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:clickable="true" 
     android:onClick="method1" 
     android:src="@drawable/button1" 
    /> 
    <ImageView 
     android:id="@+id/btn2" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:clickable="true" 
     android:onClick="method1" 
     android:src="@drawable/button2" 
    /> 
    </LinearLayout> 
    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:layout_below="@id/row1" 
     android:layout_centerHorizontal="true" 
    > 
    <ImageView 
     android:id="@+id/btn3" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:clickable="true" 
     android:onClick="method1" 
     android:src="@drawable/button3" 
    /> 
    <ImageView 
     android:id="@+id/btn4" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:clickable="true" 
     android:onClick="method1" 
     android:src="@drawable/button4" 
    /> 
    </LinearLayout> 
</RelativeLayout> 

screen at 240x320 screen at 320x480

+0

添加您的drawables,因爲我不瞭解底部框的大小變化。此外,該白盒不在您的示例佈局中。 – Kaediil

+0

嗨@Kaediil,感謝您的快速響應,白色盒子是背景的一部分,抱歉之前不提。關於drawables,我會盡快添加它們,現在我不知道它是否有幫助,但綠色/黃色框的大小爲mxpi爲50x50,ldpi爲38x38,背景大小爲是240x360(ldpi)和320x480(mdpi)。附加的圖像只是屏幕的一部分。 – maxivis

回答

0

您需要爲diff創建不同的佈局。分辨率即大屏幕使用佈局大文件夾.. 我希望this鏈接對您有所幫助。

+1

Hi @Dhaval Khant,非常感謝您的回覆,您是對的,我必須爲小屏幕和普通屏幕編寫單獨的佈局,並且我還縮放了png圖像。經過一番研究,我發現「經典位圖--PNG,JPG,GIF - 並不是固有的可擴展性。如果你沒有在」​​兼容模式「下運行,Android甚至不會嘗試根據屏幕分辨率和大小來擴展它們。 – maxivis

1

您的佈局看起來好像沒什麼問題,除了其上,否則將導致更加難以把東西在自己的位置上的背景下,白框標題。此外,RelativeLayout沒有方向,但被忽略。

在更大的屏幕截圖中,看起來白色框和屏幕頂部之間有更多空間。對我來說沒有意義的是第二排的尺寸不同。你是否100%肯定你正在加載正確的圖像在較小的截圖?

+0

嗨@momo,感謝您的回答,我不得不調整圖像大小,現在合適,並且佈局定義也是錯誤的:我爲小屏幕設備編寫了不同的佈局,並且在您看到的圖像中運行兩個屏幕的佈局是相同的。 – maxivis

0

你是否按照開發商site給出的步驟來讓你的應用程序支持多個屏幕?

+0

嗨@himanshu,感謝您的回覆,我錯過了解釋不同佈局目錄的部分,但現在工作正常。 – maxivis