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 //图像过滤blog

HINTING_OFF //关闭字体提示图片

HINTING_ON //使用字体提示ci

LINEAR_TEXT_FLAG //文本线性缩放文档

STRIKE_THRU_TEXT_FLAG //文本删除线get

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. 描述了各类指标在给定的文本字体的大小

  1. 基准点是baseline

  2. Ascent是baseline之上至字符最高处的距离

  3. Descent是baseline之下至字符最低处的距离

  4. Leading文档说的很含糊,实际上是上一行字符的descent到下一行的ascent之间的距离

  5. Top指的是指的是最高字符到baseline的值,即ascent的最大值

  6. 同上,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

相关文章
相关标签/搜索