dischargeAndroid-⾃定义view【1】(绘制圆形,矩形,椭圆图⽚)源码注释很清晰。(可以直接拷贝运⾏)
circleImageView类代码
package cc.willread.www.viewapp;
t.Context;
aphics.Bitmap;
aphics.BitmapFactory;
aphics.Canvas;
淄博会计网aphics.Color;
aphics.Paint;
aphics.Rect;
aphics.RectF;
import android.util.AttributeSet;
import android.view.View;
public class circleImageView extends View {solarwinds
健身培训机构
private Paint paint;
public circleImageView(Context context) {
super(context);
paint=new Paint();
illume
}
stuck
public circleImageView(Context context, AttributeSet attrs) {
super(context, attrs);
paint=new Paint();
}
@Override
protected void onDraw(Canvas canvas) {
/*
* ⽅法说明 drawCircle 绘制圆形 drawRect 绘制矩形 drawOval 绘制椭圆 drawPosText绘制⽂字 drawPath 绘制任意多边形
* drawLine 绘制直线 drawPoin 绘制点
*/
paint.tAntiAlias(true); // 是否抗锯齿
pearlfisherpaint.tAlpha(50); // 设置alpha不透明度,范围为0~255
paint.tColor(Color.RED);// 给画笔设置颜⾊s
// 设置画笔属性
paint.tStyle(Paint.Style.FILL);//画笔属性是实⼼圆
// paint.tStyle(Paint.Style.STROKE);//画笔属性是空⼼圆
paint.tStrokeWidth(4);//设置画笔粗细
Dcircle(canvas);//drawCircle 绘制圆形
Drect(canvas);//drawRect 绘制矩形四级分数换算
Doval(canvas);//drawOval 绘制椭圆
DposText(canvas);//drawPosText 按照既定点绘制⽂本内容
Pic(canvas);//绘制图⽚
}
// drawCircle 绘制圆形
public void Dcircle(Canvas canvas){
/
*四个参数:
great expectations
参数⼀:圆⼼的x坐标
参数⼆:圆⼼的y坐标
参数三:圆的半径
参数四:定义好的画笔
*/
canvas.drawCircle(60, 60, 50, paint);
}
//drawRect 绘制矩形
public void Drect(Canvas canvas){
/*五个参数: