Path类
android中通过Path类我们可以创建各种各样的绘图路径
路径的体现形式
案例代码
MyView.java
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.view.View;
public class MyView extends View {
public MyView(Context context) {
super(context);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);//定义画笔
Paint paint = new Paint();//设置抗拒齿功能
paint.setAntiAlias(true);//设置为蓝色
paint.setColor(0xFF0000FF);//设置为蓝色
paint.setStyle(Paint.Style.STROKE);//设置填充样式为描边
Path path = new Path();
path.addCircle(150,100,50,Path.Direction.CW);
canvas.drawPath(path,paint);//绘制路径
//文本路径
Path path2 = new Path();
paint.setTextSize(26);
path2.addCircle(150,300,50,Path.Direction.CW);
canvas.drawTextOnPath("活着就是受罪",path,
0,0,paint);
}
}
预览效果: