天天看點

螢幕尺寸和像素密度的資源限定符

以下是可以用來為不同的螢幕尺寸、像素密度和縱橫比包含可替換資源的檔案夾名稱限定符

1、螢幕尺寸  small 小于标準的3.2“的螢幕

                  medium 典型的智能手機的螢幕尺寸

                  large 比典型的智能手機的螢幕大得多的螢幕,比如平闆電腦和上網本

2、像素密度  像素密度通常是用每英寸點數來計算

                  ldpi  用于為像素密度在100~140dpi之間的螢幕存儲低密度資源

                  mdpi 用于像素密度在140~180dip之間的中等密度的螢幕

                  hdpi 用于像素密度在190~250dip之間的高密度的螢幕

                  nodpi 用于不管螢幕密度如何,都不能伸縮的資源

3、縱橫比  螢幕的縱橫比就是其高度和寬度的比率

                 long 用于橫向模式的寬度比标準智能手機(如G1)的寬度大得多的螢幕

                 notlong 用于具有典型智能手機的縱橫比的螢幕

具體描述如下表格:

螢幕尺寸和像素密度的資源限定符

每個限定符可以單獨使用也可以和其他限定符一起使用

如 res/layout-small-long   //小而長的螢幕的布局

    res/layout-large            //大螢幕的布局

    res/drawable-hdpi         //高密度螢幕的 Drawable 

    res/layout/my_layout.xml             // layout for normal screen size ("default")

    res/layout-small/my_layout.xml       // layout for small screen size

    res/layout-large/my_layout.xml       // layout for large screen size

    res/layout-xlarge/my_layout.xml      // layout for extra large screen size

    res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation

    res/drawable-mdpi/my_icon.png        // bitmap for medium density

    res/drawable-hdpi/my_icon.png        // bitmap for high density

    res/drawable-xhdpi/my_icon.png       // bitmap for extra high density

 Tip: If you have some drawable resources that the system should never scale (perhaps because you perform some adjustments to the image yourself at runtime), you should place them in a directory with the <code>nodpi</code> configuration qualifier. Resources with this qualifier are considered density-agnostic and the system will not scale them.

附:通過&lt;supports-screens android:smallScreens="false" android:normalScreens="true" android:largeScreens="true" android:anyDensity="true"/&gt;清單可以控制指定應用程式在哪些螢幕下運作

Declaring Tablet Layouts for Android 3.2

Screen configuration

Qualifier values

Description

smallestWidth(寬和高中比較小

的長度要比&lt;N&gt;大)

<code>sw&lt;N&gt;dp</code>

Examples:

<code>sw600dp</code>

<code>sw720dp</code>

The fundamental size of a screen, as indicated by the shortest dimension of the available screen area. Specifically, the device's smallestWidth is the shortest of the screen's available height and width (you may also think of it as the "smallest possible width" for the screen). You can use this qualifier to ensure that, regardless of the screen's current orientation, your application's has at least <code>&lt;N&gt;</code> dps of width available for it UI.

For example, if your layout requires that its smallest dimension of screen area be at least 600 dp at all times, then you can use this qualifer to create the layout resources, <code>res/layout-sw600dp/</code>. The system will use these resources only when the smallest dimension of available screen is at least 600dp, regardless of whether the 600dp side is the user-perceived height or width. The smallestWidth is a fixed screen size characteristic of the device; the device's smallestWidth does not change when the screen's orientation changes.

The smallestWidth of a device takes into account screen decorations and system UI. For example, if the device has some persistent UI elements on the screen that account for space along the axis of the smallestWidth, the system declares the smallestWidth to be smaller than the actual screen size, because those are screen pixels not available for your UI.

This is an alternative to the generalized screen size qualifiers (small, normal, large, xlarge) that allows you to define a discrete number for the effective size available for your UI. Using smallestWidth to determine the general screen size is useful because width is often the driving factor in designing a layout. A UI will often scroll vertically, but have fairly hard constraints on the minimum space it needs horizontally. The available width is also the key factor in determining whether to use a one-pane layout for handsets or multi-pane layout for tablets. Thus, you likely care most about what the smallest possible width will be on each device.

Available screen width

(寬度至少要比&lt;N&gt;大)

<code>w&lt;N&gt;dp</code>

<code>w720dp</code>

<code>w1024dp</code>

Specifies a minimum available width in dp units at which the resources should be used—defined by the <code>&lt;N&gt;</code> value. The system's corresponding value for the width changes when the screen's orientation switches between landscape and portrait to reflect the current actual width that's available for your UI.

This is often useful to determine whether to use a multi-pane layout, because even on a tablet device, you often won't want the same multi-pane layout for portrait orientation as you do for landscape. Thus, you can use this to specify the minimum width required for the layout, instead of using both the screen size and orientation qualifiers together.

Available screen height

(高度至少要比&lt;N&gt;大)

<code>h&lt;N&gt;dp</code>

<code>h720dp</code>

<code>h1024dp</code>

etc.

Specifies a minimum screen height in dp units at which the resources should be used—defined by the <code>&lt;N&gt;</code> value. The system's corresponding value for the height changes when the screen's orientation switches between landscape and portrait to reflect the current actual height that's available for your UI.

Using this to define the height required by your layout is useful in the same way as <code>w&lt;N&gt;dp</code> is for defining the required width, instead of using both the screen size and orientation qualifiers. However, most apps won't need this qualifier, considering that UIs often scroll vertically and are thus more flexible with how much height is available, whereas the width is more rigid.

To help you target some of your designs for different types of devices, here are some numbers for typical screen widths:

320dp: a typical phone screen (240x320 ldpi, 320x480 mdpi, 480x800 hdpi, etc).

480dp: a tweener tablet like the Streak (480x800 mdpi).

600dp: a 7” tablet (600x1024 mdpi).

720dp: a 10” tablet (720x1280 mdpi, 800x1280 mdpi, etc).

 Caution: When developing for Android 3.2 and higher, you should not use the older screen size attributes in combination with the attributes listed above. Using both the new attributes and the older size attributes might cause unexpected behavior.

繼續閱讀