Canvas被称作画布类,就可以在画布上绘制我们想要的东西了,下面介绍的有画布的一些基本属性。
public class CanvasTest extends View {
private Paint paint = null;public CanvasTest(Context context) {
super(context);
// TODO Auto-generated constructor stub
paint = new Paint();
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
canvas.drawColor(Color.GREEN);//设置画布的颜色
paint.setColor(Color.BLACK);//设置画笔的颜色
canvas.clipRect(10, 10, 200, 150);//设置裁剪区域
canvas.save();//锁定画布
canvas.rotate(45.0f);//旋转画布
canvas.restore();//解除画布的锁定
canvas.drawCircle(cx, cy, radius, paint);//绘制圆形
canvas.drawOval(oval, paint);//绘制椭圆
canvas.drawLine(startX, startY, stopX, stopY, paint);//绘制直线
canvas.drawPath(path, paint);//绘制任意多边形
canvas.drawPoint(x, y, paint);//绘制点
*/