以下是可以用来为不同的屏幕尺寸、像素密度和纵横比包含可替换资源的文件夹名称限定符
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 nodpi
configuration qualifier. Resources with this qualifier are considered density-agnostic and the system will not scale them.
附:通过<supports-screens android:smallScreens="false" android:normalScreens="true" android:largeScreens="true" android:anyDensity="true"/>清单可以控制指定应用程序在哪些屏幕下运行
Declaring Tablet Layouts for Android 3.2
Screen configuration | Qualifier values | Description |
---|---|---|
smallestWidth(宽和高中比较小 的长度要比<N>大) | sw<N>dp Examples: sw600dp sw720dp | 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 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, 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 (宽度至少要比<N>大) | w<N>dp Examples: w720dp w1024dp | Specifies a minimum available width in dp units at which the resources should be used—defined by the 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
(高度至少要比<N>大)
| h<N>dp Examples: h720dp h1024dp etc. | Specifies a minimum screen height in dp units at which the resources should be used—defined by the Using this to define the height required by your layout is useful in the same way as |
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.