今天学习下Paint这个类,决定从看源码开始学习。
先看类的定义就很有特点:public class Paint extends _Original_Paint ,后面这个_Original_Paint 是怎么个回事,希望大家解释,我不懂。
用到了Style,这个是一个内部的枚举类,有3种:FILL (0), STROKE (1), FILL_AND_STROKE (2);
/**
* The Style specifies if the primitive being drawn is filled,
* stroked, or both (in the same color). The default is FILL.
*/
public enum Style
还有Align,仍然是一个内部枚举类,还是有3个值:LEFT (0), CENTER (1), RIGHT (2);
/**
* Align specifies how drawText aligns its text relative to the
* [x,y] coordinates. The default is LEFT.
*/
public enum Align
有个Join,待解。。。
/**
* The Join specifies the treatment where lines and curve segments
* join on a stroked path. The default is MITER.
*/
public enum Join
还有个Cap,这个不知道干嘛用的,待查。。。
/**
* The Cap specifies the treatment for the beginning and ending of
* stroked lines and paths. The default is BUTT.
*/
public enum Cap
内部静态类:看代码可知,Paint和这个FontInfo关系很大
public static final class FontInfo {
Font mFont;
java.awt.FontMetrics mMetrics;
}
构造函数有三种:
public Paint() {
this(0);
}
public Paint(int flags) {
setFlags(flags | DEFAULT_PAINT_FLAGS);
initFont();
}
public Paint(Paint paint) {
set(paint);
initFont();
}
后面内容中用到了Typeface,个人认为就是一个字体样式的类,看它的源码,里面的内容比较简单。
看了看后面的方法,基本都是一些基本的方法,对字体颜色、大小、边距的设置等等。
Android 中的画笔是 Paint类,Paint 中包含了很多方法对其属性进行设置,主要方法如下:
setAntiAlias: 设置画笔的锯齿效果。
setColor: 设置画笔颜色
setARGB: 设置画笔的a,r,p,g值。
setAlpha: 设置Alpha值
setTextSize: 设置字体尺寸。
setStyle: 设置画笔风格,空心或者实心。
setStrokeWidth: 设置空心的边框宽度。
getColor: 得到画笔的颜色
getAlpha: 得到画笔的Alpha值。
Paint类介绍
*
* Paint即画笔,在绘图过程中起到了极其重要的作用,画笔主要保存了颜色,
* 样式等绘制信息,指定了如何绘制文本和图形,画笔对象有很多设置方法,