android开发PathEffect问题处理-创新互联
我要画出一块由不规则path组成的区域,并且这个path因为视觉效果需要设置圆角,我就通过Paint.setPathEffect(new CornerPathEffect(300)); 给设置了圆角,但是在通过这个path组合成区域的时候因为这个圆角的设置整个区域都有圆角的效果了,这不是我想要的。
创新互联是一家集网站建设,文成企业网站建设,文成品牌网站建设,网站定制,文成网站建设报价,网络营销,网络优化,文成网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。如图,黑色是我的path,红色是我设置了圆角的由path组成的区域。四个角落都有了圆角的效果,这不是我想要的。
而蓝色区域是未设置圆角的,此时path一侧的区域就不符合标准了。
以下是我的全部代码
public class PathEffectView extends View { private Path line; private Paint linePaint; private Path range; private Paint rangePaint; private final Paint paint3; public PathEffectView(Context context, @Nullable AttributeSet attrs) { super(context, attrs); linePaint = new Paint(Paint.ANTI_ALIAS_FLAG); linePaint.setStrokeWidth(10); linePaint.setColor(Color.BLACK); linePaint.setStyle(Paint.Style.STROKE); linePaint.setPathEffect(new CornerPathEffect(300)); rangePaint = new Paint(linePaint); rangePaint.setColor(Color.BLUE); rangePaint.setStyle(Paint.Style.FILL); paint3 = new Paint(linePaint); paint3.setColor(Color.RED); } @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); line = new Path(); range = new Path(); line.moveTo(0,1000); line.rLineTo(200,-150); line.rLineTo(200,300); line.rLineTo(200,-350); line.rLineTo(200,320); line.rLineTo(200,-370); line.lineTo(w,800); range.addPath(line); range.lineTo(w,h); rangePaint.setPathEffect(null); range.lineTo(0,h); range.close(); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.save(); canvas.translate(0,-20); canvas.drawPath(line, linePaint); canvas.restore(); canvas.drawPath(range, rangePaint); canvas.drawPath(range,paint3); } }
网站名称:android开发PathEffect问题处理-创新互联
路径分享:http://ybzwz.com/article/dcjpoc.html