用drawpath
为什么画线不用drawPath,省事多了
为什么画线不用drawPath,省事多了
2015-03-16
九宫格解锁
画线
/**
* 进行绘制
*
* @param canvas 画布
*/
@Override
protected void onDraw(Canvas canvas) {
Paint paint=new Paint(); //初始化画笔
paint.setAntiAlias(true); //抗锯齿
paint.setColor(Color.parseColor("#666666")); //画笔颜色
paint.setStyle(Paint.Style.STROKE); //画笔风格
paint.setPathEffect(new CornerPathEffect(3)); //圆角效果
paint.setStrokeWidth(20); //画笔宽度
if (!mDoneInit) {
init();
}
drawPoint(canvas);
Path path = new Path();
if (mPressPoint.size() > 0) {
//绘制已选点连线
MyPoint a = mPressPoint.get(0); //初始化a点
for (int i = 1; i < mPressPoint.size(); i++) {
MyPoint b = mPressPoint.get(i); //获取b点
path.moveTo(a.getmPX(),a.getmPY()); //设置从a点开始画
path.lineTo(b.getmPX(),b.getmPY()); //设置画到b点
canvas.drawPath(path, paint); //调用绘制函数开始绘制
a = b; //将b赋值给a 当做下一个初始点
}
//绘制与手指点连线
if (mIsMoving) {
MyPoint b = new MyPoint((int)mHandX,(int)mHandY); //将手指位置设为b点
path.moveTo(a.getmPX(),a.getmPY()); //设置从a点开始画
path.lineTo(b.getmPX(),b.getmPY()); //设置画到b点
canvas.drawPath(path, paint); //调用绘制函数开始绘制
}
}
}
举报