2012-02-24 107 views
0

我想保留res/drawable文件夾中的圖像,該文件夾將用作我應用程序中的背景。我希望我的應用能夠在各種密度的設備上工作。爲保持合理的應用尺寸和支持多個屏幕之間的平衡,應該保留圖像的像素最小尺寸。Android應用程序中的背景圖像的最小尺寸

的顯影劑導向提到:

xlarge screens are at least 960dp x 720dp 
large screens are at least 640dp x 480dp 
normal screens are at least 470dp x 320dp 
small screens are at least 426dp x 320dp 

我使用Photoshop其中圖像總是在像素和不DP和因此混亂。順便說一句,我在Android和Photoshop上都很新。

回答

0

你必須創建分辨率320x480的圖像尺寸保存在繪製-MDPI文件夾和480×800大小保存在繪製,華電國際文件夾

他們兩個尺寸的圖像運行在每個小和大屏幕設備。

中等設備320x480和高密度480x800。

0

根本不要使用固定大小的圖像。使用小圖像作爲平鋪背景或將背景定義爲漸變或使用xml資源的任何內容。

+0

感謝..但我的形象就像一個標誌,一個country..so這是很難用一個平鋪的背景,漸變或XML資源的.. – ambit 2012-02-24 07:50:45

+0

這聽起來像一個在應用程序大小和性能方面影響不大.. – 2012-02-24 18:38:31

+0

應用程序大小不是太多,因爲該應用程序非常簡單。但客戶希望帶有國旗的背景。所以,這裏沒有太多的選擇。任何想法,什麼應該是可接受的位圖圖像的大小,以便它在所有設備上看起來很好? – ambit 2012-02-25 07:19:03

1

試着研究一下9貼片image。這張單張圖片可以解決您的問題。

+0

謝謝..這是一個很好的建議。我會使用9補丁圖像。但是,再次,我應該使用單個圖像的大小(以像素爲單位)。 – ambit 2012-02-24 07:54:24

2

如果要的DP值轉換爲像素u可以使用下面的公式:

INT PX =(int)的(DP * logicalDensity + 0.5);

要從像素獲得dp,請將密度除以像素值而不是乘。

+0

謝謝。但是我不確定我應該在這個公式中使用logicalDensity。 – ambit 2012-02-24 07:56:41

0

px是一個像素。與尺寸無關的像素(sp)和與濃度無關的像素(dip),您希望使用sp來表示字體大小,並傾斜所有其他字體。浸== DP從這裏http://developer.android.com/guide/topics/resources/more-resources.html#Dimension

px 
Pixels - corresponds to actual pixels on the screen. 

in 
Inches - based on the physical size of the screen. 

mm 
Millimeters - based on the physical size of the screen. 

pt 
Points - 1/72 of an inch based on the physical size of the screen. 

dp 
Density-independent Pixels - an abstract unit that is based on the physical density of the screen. These units are relative to a 160 dpi screen, so one dp is one pixel on a 160 dpi screen. The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion. Note: The compiler accepts both "dip" and "dp", though "dp" is more consistent with "sp". 

sp 
Scale-independent Pixels - this is like the dp unit, but it is also scaled by the user's font size preference. It is recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and user's preference.