android中dip、dp、px、sp和屏幕密度
来源:互联网 发布:淘宝客服去哪里培训 编辑:程序博客网 时间:2024/06/10 07:23
1. dip: density-independent pixel(密度无关像素). 不同设备有不同的显示效果,这个和设备硬件有关,一般我们为了支持WVGA、HVGA和QVGA 推荐使用这
这个,不依赖像素。
这里要特别注意dip与屏幕密度有关,而屏幕密度又与具体的硬件有关,硬件设置不正确,有可能导致dip不能正常显示。在屏幕密度为160的显示屏上,1dip=1px,有时候可能你的屏幕分辨率很大如480*800,但是屏幕密度没有正确设置比如说还是160,那么这个时候凡是使用dip的都会显示异常,基本都是显示过小。
dip的换算:
dip(value)=(int) (px(value)/1.5 + 0.5)
2. dp: 很简单,和dip是一样的。
3. px: pixels(像素),不同的设备不同的显示屏显示效果是相同的,这是绝对像素,是多少就永远是多少不会改变。
4. sp: scaled pixels(放大像素). 主要用于字体显示best for textsize。
NOTE: 根据google的推荐,像素统一使用dip,字体统一使用sp
/** * The logical density of the display. This is a scaling factor for the * Density Independent Pixel unit, where one DIP is one pixel on an * approximately 160 dpi screen (for example a 240x320, 1.5"x2" screen), * providing the baseline of the system's display. Thus on a 160dpi screen * this density value will be 1; on a 120 dpi screen it would be .75; etc. * * <p>This value does not exactly follow the real screen size (as given by * {@link #xdpi} and {@link #ydpi}, but rather is used to scale the size of * the overall UI in steps based on gross changes in the display dpi. For * example, a 240x320 screen will have a density of 1 even if its width is * 1.8", 1.3", etc. However, if the screen resolution is increased to * 320x480 but the screen size remained 1.5"x2" then the density would be * increased (probably to 1.5). * * @see #DENSITY_DEFAULT */ public float density;来看一段DisplayMetrics类中的解释,160dpi的设备作为基准,其它的根据这个来进行缩放。如密度为320的,则缩放因子为320/160=2.0;如密度为120,则因子为120/160=0.75。
在缩放因子为1的设备上,1dp=1px;
在缩放因子为2的设备上,1dp=2px;
如此类推。
在一些设备上,X方向和Y方向的密度不一样,如X方向的密度可能是1.5,Y方向的密度是2.0,这样一来我们在适配手机屏幕时就需要根据X,Y的密度分别来设置。
- android中dip、dp、px、sp和屏幕密度
- android中dip、dp、px、sp和屏幕密度
- android中dip、dp、px、sp和屏幕密度
- android中dip、dp、px、sp和屏幕密度
- android中dip、dp、px、sp和屏幕密度
- android中dip、dp、px、sp和屏幕密度
- android中dip、dp、px、sp和屏幕密度
- android中dip、dp、px、sp和屏幕密度
- android中dip、dp、px、sp和屏幕密度
- android中dip、dp、px、sp和屏幕密度
- android中dip、dp、px、sp和屏幕密度
- android中dip、dp、px、sp和屏幕密度详解
- android中dip、dp、px、sp和屏幕密度
- (转)android中dip、dp、px、sp和屏幕密度
- android中dip、dp、px、sp和屏幕密度简介
- android中dip、dp、px、sp和屏幕密度
- android中dip、dp、px、sp和屏幕密度
- android中dip、dp、px、sp和屏幕密度
- 数据库表设计--1(测试结构)
- string类的一些常用成员函数
- 用VirtualBox实现xp下多系统(dsl linux安装)图文教程
- java学习 --接口的多重继承
- div各种属性
- android中dip、dp、px、sp和屏幕密度
- FIX标准的工作流服务组件
- 在VMware server 中安装 CentOS5.6+Oracle11gR2 swap 空间不够,增加swap 空间
- binder 进程间通讯关于handle一点疑问?(自己已经弄明白了一点)
- ccs中的cmd
- How to use an ASP.NET application to query an Indexing Service catalog by using Visual Basic .NET
- 养成好的习惯
- 使用System.Transactions
- 操作datatable进行分页,绑定repeqter或者gridView