屏幕尺寸和像素密度的资源限定符

简介: 以下是可以用来为不同的屏幕尺寸、像素密度和纵横比包含可替换资源的文件夹名称限定符 1、屏幕尺寸  small 小于标准的3.2“的屏幕                   medium 典型的智能手机的屏幕尺寸                   large 比典型的智能手机的屏幕大得多的屏幕...

以下是可以用来为不同的屏幕尺寸、像素密度和纵横比包含可替换资源的文件夹名称限定符

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 <N> 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, res/layout-sw600dp/. 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

(宽度至少要比<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 <N> 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

 

(高度至少要比<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 <N> 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 w<N>dp 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.

相关文章
|
7月前
|
编解码 UED
描述一下你是如何处理不同屏幕尺寸和分辨率的。
```markdown 使用响应式设计、媒体查询适应屏幕尺寸;利用弹性布局保证元素自适应;通过图像适配提供高质量视图;多设备测试与优化确保兼容性,持续关注新技术以应对屏幕多样性。 ```
59 3
|
1月前
|
前端开发 开发者 UED
设备像素、css像素、设备独立像素、dpr、ppi之间的区别
【10月更文挑战第24天】在实际应用中,这些概念相互关联,共同影响着网页在不同设备上的显示表现。开发者需要了解它们之间的区别和关系,以便更好地进行网页设计和优化,确保在各种设备上都能提供良好的用户体验。
|
编解码 前端开发 JavaScript
说说设备像素、css像素、设备独立像素、dpr、ppi之间的区别?
说说设备像素、css像素、设备独立像素、dpr、ppi之间的区别?
字体等比例缩小
字体等比例缩小
70 0
|
编解码 前端开发
图文并茂带你弄懂物理分辨率、分辨率、物理像素、逻辑像素、dpr、ppi
物理分辨率和分辨率 什么是物理像素 什么是CSS像素 什么是设备像素比 什么是标清屏和高清屏 缩放 什么是PPI(DPI)
490 0
|
JavaScript
问题解决:百分比宽度页面缩放会变形
问题解决:百分比宽度页面缩放会变形
235 1
问题解决:百分比宽度页面缩放会变形
|
编解码 前端开发 JavaScript
【CSS】聊一聊CSS像素、设备像素、设备独立像素、dpr、ppi 之间的区别
前言 大家好,我是HoMeTown,顺着计量单位,想继续聊一下CSS像素、设备像素、设备独立像素、dpr、ppi 之间的区别。
202 0
|
编解码 前端开发 Android开发
像素相关概念:PPI、DPI、设备像素、独立像素
像素相关概念:PPI、DPI、设备像素、独立像素
234 0
像素相关概念:PPI、DPI、设备像素、独立像素
|
XML 编解码 Android开发
【Android 应用开发】Android屏幕适配解析 - 详解像素,设备独立像素,归一化密度,精确密度及各种资源对应的尺寸密度分辨率适配问题(二)
【Android 应用开发】Android屏幕适配解析 - 详解像素,设备独立像素,归一化密度,精确密度及各种资源对应的尺寸密度分辨率适配问题(二)
270 0
【Android 应用开发】Android屏幕适配解析 - 详解像素,设备独立像素,归一化密度,精确密度及各种资源对应的尺寸密度分辨率适配问题(二)
|
Android开发
【Android 内存优化】Bitmap 图像尺寸缩小 ( 考虑像素密度、针对从不同像素密度资源中解码对应的 Bitmap 对象 | inDensity | inTargetDensity )
【Android 内存优化】Bitmap 图像尺寸缩小 ( 考虑像素密度、针对从不同像素密度资源中解码对应的 Bitmap 对象 | inDensity | inTargetDensity )
307 0