虚拟像素单位, 用于定义应用的UI, 以密度无关的方式表达布局尺寸或位置.
android官方定义dip等价于160dpi屏幕下的一个物理像素点.
在运行时, android根据使用中的屏幕的实际密度, 透明地处理任何所需dp单位的缩放.
dp到屏幕像素的转换公式: pixels = dps * (density / 160).
举例来说, 在 240 dpi 的屏幕上, 1dp 等于 1.5物理像素.
强烈推荐使用dp单位来定义你的应用UI, 这是确保你的UI在不同屏幕上显示的一个好方法.
- Android平台划分几个的实际支持的屏幕尺寸和分辨率范围
- 4个通用尺寸:
- small: 至少 426dp x 320dp
- normal: 至少 470dp x 320dp
- large: 至少 640dp x 480dp
- xlarge: 至少 960dp x 720dp -- Android 2.3 (API Level 9)
- 4个通用屏幕密度:
- ldpi (low)
- mdpi (medium)
- hdpi (high)
- xhdpi (extra high): -- Android 2.2 (API Level 8)
- 4个通用尺寸:
图1: Android平台如何将真实屏幕密度和大小映射到通用的密度和尺寸配置.
表 1. Android SDK中包含的模拟器皮肤的屏幕尺寸和密度,以及其他典型的分辨率.
2 ~ 3.5 inch | QVGA (240x320) | 480x640 | ||
3+ ~ 4.5 inch |
WQVGA400 (240x400) WQVGA432 (240x432) |
HVGA (320x480) |
WVGA800 (480x800) WVGA854 (480x854) 600x1024 |
640x960 |
4+ ~ 7 inch |
WVGA800** (480x800) WVGA854** (480x854) |
WVGA800* (480x800) WVGA854* (480x854) 600x1024 |
||
7 ~ 10+ inch | 600x1024 | 768x1024 WXGA (768x1280) 800x1280 |
1152x1536 1152x1920 1200x1920 |
1536x2048 1536x2560 1600x2560 |
* 要模拟此配置, 使用WVGA800 或 WVGA854创建一个AVD, 指定自定义密度160.
** 要模拟此配置, 使用WVGA800 或 WVGA854创建一个AVD, 指定自定义密度120.
ps: 增加辅助工具类:
- import android.content.Context;
- public class DensityUtil {
- public static int dip2px(Context context, float dpValue) {
- final float scale = context.getResources().getDisplayMetrics().density;
- return (int) (dpValue * scale + 0.5f);
- }
- public static int px2dip(Context context, float pxValue) {
- final float scale = context.getResources().getDisplayMetrics().density;
- return (int) (pxValue / scale + 0.5f);
- }
- }
相关推荐
dip/px互转工具
android开发之dip,dp与px像素之间的转换工具,博文介绍:http://blog.csdn.net/qq_21376985/article/details/51704703
dip dp px sp区别 dip dp px sp区别 dip dp px sp区别
描述android的dip dp px dp等单位及其转换关系
1. dip: device independent pixels(设备独立像素). 不同设备有不同的显示效果,这个和设备硬件有关,一般我们为了支持WVGA、HVGA和QVGA 推荐使用这个,不依赖像素。 这里要特别注意dip与屏幕密度有关,而屏幕密度又...
dip转换工具,像素和dip相互转化工具
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" > <RelativeLayout xmlns:...
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <solid android:color="#55000000"/> android:angle="270" android:type="linear" android:endColor="#...
手机分辨率基础知识(DPI,DIP计算) 1.术语和概念 术语 说明 备注 Screen size(屏幕尺寸) 指的是手机实际的物理尺寸,比如常用的2.8英寸,3.2英寸,3.5英寸,3.7英寸 摩托罗拉milestone手机是3.7英寸 ...
Android的计量单位px,in,mm,pt,dp,dip,sp Android的计量单位px,in,mm,pt,dp,dip,sp
dip和具体像素值的对应公式是dip/pixel=dpi值/160,也就是px = dp * (dpi / 160) 当你定义应用的布局的UI时应该使用dp单位,确保UI在不同的屏幕上正确显示。 手机屏幕分类和像素密度的对应关系如表1所示 目前...
android:width设置文本区域的宽度,支持度量单位:px(像素)/dp/sp/in/mm(毫米),与layout_width的区别看这里。 android:maxWidth设置文本区域的最大宽度 android:minWidth设置文本区域的最小宽度 android...
xmlns:android="http://schemas.android.com/apk/res/android"> android:layout_width="fill_parent" android:layout_height="46.0dip" android:layout_marginBottom="-1.0dip" android:src="@drawab
本资源适应以下分辨率的android设备,不管android设备尺寸大小 像素宽 =1024 高 =720 ...方法:先得到手机屏幕的像素px,再根据像素PX得到 手机屏幕的独立像素dip,然后根据dip计算来相应布局,就能得到你想要适应的像素
2、度量单位含义dip: device independent pixels(设备独立像素). 不同设备有不同的显示效果,这个和设备硬件有关,一般我们为了支持WVGA、HVGA和QVGA 推荐使用这个,不依赖像素。 dp: dip是一样的px: pixels
NULL 博文链接:https://1307111376.iteye.com/blog/1986752
Andrid上dip、dp、px、sp等单位说明,有助于同学们对各个单位的了解
dp (dip): 即设备无关像素(device independent pixels),这种尺寸单位在不同设备上的物理大小相同。 px:即像素(pixel),这个不用多说。 pt:通常用来作为字体的尺寸单位,1 pt相当于1/72英寸。 inch:英寸...
dp(dip): device independent pixels(设备独立像素). 不同设备有不同的显示效果,这个和设备硬件有关,一般我们为了支持WVGA、HVGA和QVGA 推荐使用这个,不依赖像素。dp也就是dip,这个和sp基本类似。如果设置表示...