您的位置:首页 > 移动开发 > Android开发

android drawable( hdpi, ldpi, mdpi, xhdpi, xxhdpi)区别

2015-06-24 16:36 1281 查看
不同点在于,图片资源文件被细分了。系统会根据dip的大小选择对应目录下的资源文件。

drawable-hdpi 对应DPI为 (~240dpi).

drawable-ldpi 对应DPI为(~120dpi)

drawable-mdpi 对应DPI为 (~160dpi)

drawable-xhdpi 对应DPI为 (~320dpi).

drawable-xxhdpi
对应DPI为(~480dpi)

drawable-xxxhdpi
对应DPI为(~640dpi)

nodpi
:Resources for all densities. These are density-independent resources. The system does not scale resources tagged with this qualifier, regardless of the current screen's density.

tvdpi
:Resources for screens somewhere between mdpi and hdpi; approximately 213dpi. This is not considered a "primary" density group. It is mostly intended for televisions and most apps shouldn't
need it—providing mdpi and hdpi resources is sufficient for most apps and the system will scale them as appropriate. If you find it necessary to provide tvdpi resources, you should size them at a factor of 1.33*mdpi. For example, a 100px x 100px image for
mdpi screens should be 133px x 133px for tvdpi.


Alternative drawables



Figure 4. Relative sizes for bitmap drawables that support each density.

Almost every application should have alternative drawable resources for different screen densities, because almost every application has a launcher icon and that icon should look good on all screen densities. Likewise, if you include other bitmap drawables
in your application (such as for menu icons or other graphics in your application), you should provide alternative versions or each one, for different densities.

Note: You only need to provide density-specific drawables for bitmap files (
.png
.jpg
, or 
.gif
) and Nine-Patch files (
.9.png
). If you use XML files to
define shapes, colors, or other drawable resources, you should put one copy in the default drawable
directory (
drawable/
).

To create alternative bitmap drawables for different densities, you should follow the 3:4:6:8:12:16 scaling ratiobetween the six generalized densities. For example, if you have a bitmap drawable that's 48x48 pixels for medium-density screens,
all the different sizes should be:
36x36 (0.75x) for low-density
48x48 (1.0x baseline) for medium-density
72x72 (1.5x) for high-density
96x96 (2.0x) for extra-high-density
180x180 (3.0x) for extra-extra-high-density
192x192 (4.0x) for extra-extra-extra-high-density (launcher icon only; see note above)

For more information about designing icons, see the Icon Design Guidelines, which includes size information
for various bitmap drawables, such as launcher icons, menu icons, status bar icons, tab icons, and more.


How to Test Your Application on Multiple Screens

Figure 6. A set of AVDs for testing screens support.

Before publishing your application, you should thoroughly test it in all of the supported screen sizes and densities. The Android SDK includes emulator skins you can use, which replicate the sizes and densities of common screen configurations on which your
application is likely to run. You can also modify the default size, density, and resolution of the emulator skins to replicate the characteristics of any specific screen. Using the emulator skins and additional custom configurations allows you to test any
possible screen configuration, so you don't have to buy various devices just to test your application's screen support.

To set up an environment for testing your application's screen support, you should create a series of AVDs (Android Virtual Devices), using emulator skins and screen configurations that emulate the screen sizes and densities you want your application to support.
To do so, you can use the AVD Manager to create the AVDs and launch them with a graphical interface.

To launch the Android SDK Manager, execute the 
SDK Manager.exe
 from your Android SDK directory (on Windows
only) or execute 
android
 from the 
<sdk>/tools/
 directory
(on all platforms). Figure 6 shows the AVD Manager with a selection of AVDs, for testing various screen configurations.

Table 3 shows the various emulator skins that are available in the Android SDK, which you can use to emulate some of the most common screen configurations.

For more information about creating and using AVDs to test your application, see Managing AVDs with AVD Manager.

Table 3. Various screen configurations available from emulator skins in the Android SDK (indicated in bold) and other representative resolutions.
Low density (120), ldpi
Medium density (160), mdpi
High density (240), hdpi
Extra-high-density (320), xhdpi
SmallscreenQVGA (240x320)480x640
NormalscreenWQVGA400 (240x400) 
WQVGA432 (240x432)
HVGA (320x480)WVGA800 (480x800) 
WVGA854 (480x854) 

600x1024
640x960
LargescreenWVGA800** (480x800) 
WVGA854** (480x854)
WVGA800* (480x800) 
WVGA854* (480x854) 

600x1024
Extra-Largescreen1024x600WXGA (1280x800)†

1024x768

1280x768
1536x1152

1920x1152 

1920x1200
2048x1536

2560x1536 

2560x1600
* To emulate this configuration, specify a custom density of 160 when creating an AVD that uses a WVGA800 or WVGA854 skin.

** To emulate this configuration, specify a custom density of 120 when creating an AVD that uses a WVGA800 or WVGA854 skin.

† This skin is available with the Android 3.0 platform
To see the relative numbers of active devices that support any given screen configuration, see the Screen Sizes and
Densities dashboard.

Figure 7. Size and density options you can set, when starting an AVD from the AVD Manager.

We also recommend that you test your application in an emulator that is set up to run at a physical size that closely matches an actual device. This makes it a lot easier to compare the results at various sizes and densities. To do so you need to know the approximate
density, in dpi, of your computer monitor (for instance, a 30" Dell monitor has a density of about 96 dpi). When you launch an AVD from the AVD Manager, you can specify the screen size for the emulator and your monitor dpi in the Launch Options, as shown in
figure 7.

If you would like to test your application on a screen that uses a resolution or density not supported by the built-in skins, you can create an AVD that uses a custom resolution or density. When creating the AVD from the AVD Manager, specify the Resolution,
instead of selecting a Built-in Skin.

If you are launching your AVD from the command line, you can specify the scale for the emulator with the 
-scale
 option.
For example:
emulator -avd <avd_name> -scale 96dpi


To refine the size of the emulator, you can instead pass the 
-scale
 option a number between 0.1 and 3
that represents the desired scaling factor.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: