1、Android中单位介绍

根据官网介绍(https://developer.android.com/guide/topics/resources/more-resources.html#Dimension),Android中可用单位有:

dp(Density-independent-Pixels);

An abstract unit that is based on the physical density of the screen.

基于物理屏幕密度的抽象单位。

sp(Scale-independent-Pixels);

This is like the dp unit, but it is also scaled by the user's font size preference.

和dp一样,但是还根据用户选择的字体大小选项缩放。

pt(Points);

1/72 of an inch based on the physical size of the screen, assuming a 72dpi density screen.

表示在屏幕上的1/72英寸,也是72屏幕密度。

(dpi:dots per inch)

px(Pixels);

Corresponds to the actual pixels on the screen.

in(Inches);

英寸

mm(MiliMeters);

毫米


2、Android中常用

Android中表示长度、宽度常用dp,字体大小常用sp。

因为这两个不是实际单位,会随着屏幕密度变化而变化,所以对于不同屏幕的适配很方便。


3、dp、sp、pt转换

px = (density/160)dp.

在160dpi下,1dp几乎等于1px,随着屏幕密度的变化,dp与sp的比例也随之缩放。

在160dpi下,

     1dp = 1px;

     1sp = 1px;

     1pt = 72dpi;

     1pt = 2.22sp.     【1in有160px(dp/sp),1pt = 1/72in(72dpi) ——> 1pt = 2.22sp】


更多相关文章

  1. Android取得系统信息和分辨率内存信息
  2. Android屏幕自适应的四种方法
  3. 在LinearLayout中嵌套RelativeLayout来设置Button的位置(xml文件)
  4. android-详解Android中的屏幕方向
  5. 详解Android中的屏幕方向
  6. 在LinearLayout中嵌套RelativeLayout来设置Button的位置(xml文件)
  7. Android屏幕相关设置
  8. Android(安卓)判断SD卡是否存在及容量查询
  9. 【Android】如何调节屏幕亮度,关闭屏幕

随机推荐

  1. 温故而知新Android篇之二
  2. Android设计尺寸规范--Android Design Gu
  3. Android 限定 Activity 转向
  4. androidの布局控件居于最底部实现
  5. Android 滚动Tab
  6. Android中的基本组件(2)
  7. Android TimePicker
  8. 由浅入深研究Android(3)--浅谈线程的一些东
  9. Android控件之CheckBox(复选框控件)
  10. Android中按钮点击效果显示