Android自定义View之paint(一)
学习自定义view,就是将view绘成自己想要的样子,自然就要有绘画的工具,那就是Paint。
- **1. 构造函数 ** Paint() Create a new paint with default settings. 创建一个默认的Paint对象 Paint(int flags) Create a new paint with the specified flags. 创建一个指定flag的Paint对象 Paint(Paint paint) Create a new paint, initialized with the attributes in the specified paint parameter 创建一个paint,并在指定的paint参数中初始化属性
- 2.flags
ANTI_ALIAS_FLAG //消除锯齿
DITHER_FLAG //防抖动
EMBEDDED_BITMAP_TEXT_FLAG //点阵字体
FAKE_BOLD_TEXT_FLAG //粗体属性
FILTER_BITMAP_FLAG //图像过滤
HINTING_OFF //关闭字体提示
HINTING_ON //使用字体提示
LINEAR_TEXT_FLAG //文本线性缩放
STRIKE_THRU_TEXT_FLAG //文本删除线
SUBPIXEL_TEXT_FLAG //文本亚像素
UNDERLINE_TEXT_FLAG //文本下划
使用方法: new Paint(Paint.flag)或者调用setFlag(int flag)
- 3.Paint 涉及的几个类(Nested classes)
enum Paint.Align
Align specifies how drawText aligns its text relative to the [x,y] coordinates.
枚举 文本方向:CENTER、LEFT(默认)、RIGHT
enum Paint.Cap
The Cap specifies the treatment for the beginning and ending of stroked lines and paths.
枚举 笔刷样式: BUTT(默认) 、ROUND、 SQUARE
如图:
**class Paint.FontMetrics **
Class that describes the various metrics for a font at a given text size. 描述了各种指标在给定的文本字体的大小
-
基准点是baseline
-
Ascent是baseline之上至字符最高处的距离
-
Descent是baseline之下至字符最低处的距离
-
Leading文档说的很含糊,其实是上一行字符的descent到下一行的ascent之间的距离
-
Top指的是指的是最高字符到baseline的值,即ascent的最大值
-
同上,bottom指的是最下字符到baseline的值,即descent的最大值 为了方便理解,从网上找个各种图片
![]
![]
**class Paint.FontMetricsInt **
一句话 FontMetricsInt就是为调用者提供将FontMetricsInt 值作为整数的便捷方法
**enum Paint.Join **
The Join specifies the treatment where lines and curve segments join on a stroked path.
枚举 连接类型:BEVEL、MITER(默认)、ROUND
![![![![![
**enum Paint.Style **
The Style specifies if the primitive being drawn is filled, stroked, or both (in the same color).
枚举 画笔类型:FILL(默认)、FILL_AND_STROKE、STROKE
从图上看 前两个并没有什么区别,画图时FILL与STROKE一起使用会达到一下效果
参考链接:http://mikewang.blog.51cto.com/3826268/871765
转载于:https://my.oschina.net/u/2483853/blog/842068