android 自定义paint,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 如图:

495834a7f373a6c72944ff373652bdef.png

**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的最大值 为了方便理解,从网上找个各种图片

112433bcf6bc206d40a02bfa6b598866.png

![

14e26b00fe9147e79e67c9d196fc37cc.png]

dd86899118610d65ac52bacfeeaa41f2.png

828de125f3a9112e04330179bd1af53f.png

7128497da33e476141f6e54831a621a1.png

![

75d17c933a723d8d2b948455fe7fca75.png]

f8bdbf3d318abc6612bbd0ba55131463.png

**class Paint.FontMetricsInt **

0840be0496aff4def27e852a8023f242.png

一句话 FontMetricsInt就是为调用者提供将FontMetricsInt 值作为整数的便捷方法

**enum Paint.Join **

The Join specifies the treatment where lines and curve segments join on a stroked path. 枚举 连接类型:BEVEL、MITER(默认)、ROUND ![![![![![

13bc64f0c9fd41990619de7efda62de0.png

**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

f6c202bfb8403a2f78340ffb00f30c49.png

从图上看 前两个并没有什么区别,画图时FILL与STROKE一起使用会达到一下效果

ec682a4194fc89d736106509202aa9b4.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值