闲谈自定义控件源码-view 坐标
来源:互联网 发布:数学分析教材推荐知乎 编辑:程序博客网 时间:2024/05/22 05:17
自定义view中 尤其是Ondraw和做动画的时候,基本上都在和坐标打交道
一、2个概念的区分 density densitydpi
区分两个概念
首先可以看一个类 DisplayMetrics Display:显示 展示的意思 Metrics:度量。可见这是一个关于屏幕度量的类
density和densityDpi是该类的两个成员变量
/**
* 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;
/**
* The screen density expressed as dots-per-inch. May be either
* {@link #DENSITY_LOW}, {@link #DENSITY_MEDIUM}, or {@link #DENSITY_HIGH}.
*/
public int densityDpi;
根据注释可以看出 densityDpi:dots-per-inc 即:每英寸像素数量 即在屏幕上y轴2.54cm长度所包含的像素数
density:densityDpi/160 ---dp 为px*density 由此看见在任何分辨率手机上一英寸的dp长度是固定的。
二、View的定位
view是根据left top right bottom来定位位置的。
可以参考网上的一篇博客,讲解的很详细:http://blog.csdn.net/yanbober/article/details/50419117/
0 0
- 闲谈自定义控件源码-view 坐标
- 闲谈自定义控件源码-view 测量
- 闲谈自定义控件源码-view layout draw
- 闲谈自定义控件源码-view如何展示在界面上
- 自定义控件,自定义View
- 自定义控件View之onMeasure调用时机源码分析
- Android自定义控件热身——View的坐标位置和大小详解
- Android自定义控件热身——View的坐标位置和大小详解
- 继承View自定义控件
- Android自定义View控件
- 自定义view控件 TypedArray
- 自定义View和控件
- Android自定义View控件
- 自定义控件View
- Android自定义View控件
- Android自定义View控件
- 自定义控件View
- 自定义控件-继承View
- 轻松理解MYSQL MVCC 实现机制
- 图像边缘检测技术与理论发展脉络梳理
- V4L2介绍
- mysql基础:1、windows系统安装mysql数据库
- line vty的原理配置及相关操作
- 闲谈自定义控件源码-view 坐标
- Tomcat环境配置部署测试环境及架构
- 在Eclipse中用Maven创建Web工程(tomcat:run 启动)
- FFT(内有dalao题解地址)
- Activity横竖屏切换的生命周期
- Linux redis服务基本配置操作
- mysql jdbc 连接数据库
- Linux脚本使用find 查找文件
- 递推递归练习N青蛙过河