android学习 4-25使用Path 绘制几何图形

package com.mz.canvas;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Paint.Style;
import android.graphics.Path.Direction;
import android.view.View;

public class MyPathView extends View {
    private Paint paint;
    private Paint paint1;

    public MyPathView(Context context) {
        super(context);
        paint=new Paint();
        paint.setColor(Color.RED);//画笔颜色
        paint.setStrokeWidth(2);//画笔宽度
        paint.setAntiAlias(true);//抗锯齿
        paint.setStyle(Style.STROKE);//样式不填充
        paint.setTextSize(20);//字体大小为20
        paint1=new Paint(paint);//继承paint
        paint1.setColor(Color.BLUE);
        // TODO Auto-generated constructor stub
    }

    @Override
    protected void onDraw(Canvas canvas) {
        // TODO Auto-generated method stub
        super.onDraw(canvas);
        canvas.drawColor(Color.WHITE);
        Path path=new Path();//实例化path
        path.addCircle(100, 100, 80, Direction.CW);//圆心坐标,半径,方向)
        //圆心100 100 顺时针
        //注意:(在参数提示中发现 有 类 定义,应该先写类名.提示)
        path.addCircle(250, 250, 50, Direction.CW);
        canvas.drawPath(path, paint);
        String str="XX大学计算机学院";
        canvas.drawTextOnPath(str, path, 270, 20, paint);//以圆写字
        //字

        //绘制一个三角形
        Path path1=new Path();
        path1.moveTo(200, 220);
        path1.lineTo(70, 300);
        path1.lineTo(280, 300);
        path1.close();//自动连线
        canvas.drawPath(path1, paint);
    }


}

你可能感兴趣的:(android)