`
fly_ever
  • 浏览: 149929 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Android中的尺寸单位

阅读更多
Dimension
A dimension value defined in XML. A dimension is specified with a number followed by a unit of measure. For example: 10px, 2in, 5sp. The following units of measure are supported by Android:

dp
dp 是与密度无关的像素,基于屏幕密度的抽象单位。在每英寸160个点的屏幕上,1dp与1px大致相等。当运行在更高/更低密度的屏幕上,1dp中的像素数根据屏幕的dpi(dots per inch)数而按比例决定。这个dp与(pixel)像素比例根据屏幕密度而变化。使用dp单位(而不是px单位) 是一个简单的解决方法,使我们的布局能自适应不同的屏幕密度,在不同的设备间能保持一致的展示真实的UI元素的尺寸。
Density-independent Pixels - An abstract unit that is based on the physical density of the screen. These units are relative to a 160 dpi (dots per inch) screen, on which 1dp is roughly equal to 1px. When running on a higher density screen, the number of pixels used to draw 1dp is scaled up by a factor appropriate for the screen's dpi. Likewise, when on a lower density screen, the number of pixels used for 1dp is scaled down. The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion. Using dp units (instead of px units) is a simple solution to making the view dimensions in your layout resize properly for different screen densities. In other words, it provides consistency for the real-world sizes of your UI elements across different devices.


sp
sp 是与刻度无关的像素,与dp类似,建议使用sp来用于用户的字体,这样也可以根据屏幕密度和用户的字体大小设置来调整。
Scale-independent Pixels - This is like the dp unit, but it is also scaled by the user's font size preference. It is recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and the user's preference.


pt
pt,1/72 英寸。
Points - 1/72 of an inch based on the physical size of the screen.

px
px,像素,屏幕上的真实像素,在真实环境中,使用不同的设备显示时,不建议使用。不同的设备显示效果不同。
Pixels - Corresponds to actual pixels on the screen. This unit of measure is not recommended because the actual representation can vary across devices; each devices may have a different number of pixels per inch and may have more or fewer total pixels available on the screen.

mm
Millimeters - Based on the physical size of the screen.
in
Inches - Based on the physical size of the screen.
0
4
分享到:
评论

相关推荐

    Android万能尺寸适配方法 以px为单位适配,你也可以根据自己的需求改成dp为单位的适配

    Android万能尺寸适配方法 以px为单位适配,你也可以根据自己的需求改成dp为单位的适配 http://blog.csdn.net/prczhb/article/details/76737407

    Android中的常用尺寸单位(dp、sp)快速入门教程

    Android开发中的常用尺寸单位有如下几种: dp (dip) px pt inch sp 算不知道确切含义,相信对于以上这几种尺寸单位大家也都比较脸熟,这里先让我们重新认识一下它们: dp (dip): 即设备无关像素(device ...

    Android自定义控件单位尺寸实现代码

    主要介绍了Android自定义控件单位尺寸实现代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

    Android:Drawable样式和尺寸单位源代码

    Android:Drawbable样式代码实例

    新版Android开发教程.rar

    ----------------------------------- Android 编程基础 1 封面----------------------------------- Android 编程基础 2 开放手机联盟 --Open --Open --Open --Open Handset Handset Handset Handset Alliance ...

    Android开发实验---通讯录.docx

    实验设备及软件: 一台电脑,Androidstudio2.3.3软件 实验方法(原理、流程图) 实现的通讯录功能和界面可在实验开发中由每位同学自己设计,但必须使用 SQLite 数据库保存通讯录信息。 以下功能和软件界面供参考:...

    Android UI规范

    任何时候,每当用户触摸您应用中的可操作区域,都应当给予视觉上的响应。这样可以使得用户了解他触摸了啥,并且表明您的应用一直在工作。 按钮的状态 大多数的 Android UI 元素都有内置的触摸反馈效果,包括表明...

    Android studio界面设计与资源PPT

    (1)理解Android屏幕元素的层次结构、View与ViewGroup (2)熟悉Android的布局...(4)熟悉Android尺寸的单位 (5)掌握TextView、EditText、Button、DatePicker、TimePicker等常用控件的功能、基本属性以及重要方法

    Android生成适配各种分辨率的dimen源文件

    自己写了一个Java文件用于生成适配各种Android屏幕分辨率的dimen尺寸,以px为单位,在res文件夹下创建“values-分辨率,如:values-1280x720”的文件再将生成的文件放进去,原理很简单,易懂

    修改系统density、densityDpi适配

    文章目录一、简述二、追根溯源三、实现3.1 定义Density用于对系统类值的修改3.2 在MainActivity中调用3.3 处理应用程序关于字体大小的监听3.4...每个控件的显示,dp、sp等最终都会转换成px为单位,原因在于android源码T

    Android屏幕适配工具类 Android自动生成不同分辨率的值

    然后根据不同的尺寸在dimens.xml文件夹中分别计算配置不同的dp或者sp单位。开发中发现,android屏幕适配需要用到很多的尺寸,每个尺寸都建立dimens.xml问价。每个文件中的数值都要按照比例去计算,一个一个拿着...

    android群雄传

    7.6.4 Android中使用SVG 177 7.6.5 SVG动画实例 181 7.7 Android动画特效 188 7.7.1 灵动菜单 188 7.7.2 计时器动画 190 7.7.3 下拉展开动画 191 第8章 Activity与Activity调用栈分析 195 8.1 Activity 196 ...

    android-opus-codec:使用JNI在Android中用C ++实现Opus编码器和解码器

    不同的镜架尺寸。 单声道或立体声输入音频。 以字节或短裤为单位输入。 以字节或短裤为单位输出。 从字节转换为短裤,反之亦然。 比特率设置。 复杂度设置。 支持的ABI: armeabi-v7a,arm64-v8a,x86,x86_...

    Android开发人员不得不收集的代码

    getAndroidID : 获取设备 AndroidID getMacAddress : 获取设备 MAC 地址 getManufacturer : 获取设备厂商 getModel : 获取设备型号 shutdown : 关机 reboot : 重启 reboot2Recovery : 重启到 recovery reboot2...

    android系统如何自适应屏幕大小

    android将实际的屏幕密度分为四个通用尺寸(low,medium,high,and extra high) 一般情况下的普通屏幕:ldpi是120dpi,mdpi是160dpi,hdpi是240dpi,xhdpi是320dpi 对于屏幕来说,dpi越大,屏幕的精细度越高,...

    工程硕士学位论文 基于Android+HTML5的移动Web项目高效开发探究

    目前市场业务中在产品以及其他项目的认证和检测方面存在诸多不便,用户需要实地考察并频繁与检测单位沟通,填写繁琐的纸质检测报告、当面送递样品,对于检测环节中存在的问题难以及时交互并处理。市场上相应的检测...

    RandRoidGrid:Android 网格视图,以不同尺寸和形状的正方形和矩形随机显示一组视图

    #RandRoidGrid Android UI 布局在随机框中显示视图。 有 4 种类型的框可能以不同的随机顺序出现在布局中: 大正方形:(2 个单位 x 2 个单位)。 小正方形:(1 个单位 x 1 个单位)。 垂直矩形:(1 个单位 x 2 个...

    android折线图

    //界面布局的尺寸的比例 111 // set up paint 112 Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); 113 paint.setColor(Color.GRAY); 114 paint.setStrokeWidth(1); 115 paint.setStyle(Style....

Global site tag (gtag.js) - Google Analytics