我正在尝试做的是用两条边用黑色笔划线的透明线条突出显示路线
到目前为止,玩不同的填充样式和Paint设置并没有让我找到任何解决方案.
有谁知道我需要找什么方向?
目前我设法只绘制实线,但这不是我想要的:
油漆设置:
mPaint.setStyle(Paint.Style.stroke);mPaint.setcolor(color_DEFAulT);mPaint.setPathEffect(new CornerPathEffect(10));mPaint.setstrokeWIDth(6);mPaint.setAntiAlias(true);
绘图程序
canvas.drawPath(mPath,mPaint);解决方法 使用“破折号标记”(两个非常薄的矩形和MORPH样式选项),PathDashPathEffect得到了相当不错的结果.在这里查看最后一行和第三行:
这是通过修改从SDK获取的APIDemos中的PathEffects示例得出的:
package com.example.androID.APIs.graphics;import androID.content.Context;import androID.graphics.*;import androID.os.Bundle;import androID.vIEw.KeyEvent;import androID.vIEw.VIEw;public class PathEffects extends GraphicsActivity { @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(new SampleVIEw(this)); } private static class SampleVIEw extends VIEw { private Paint mPaint; private Path mPath; private PathEffect[] mEffects; private int[] mcolors; private float mPhase = 3; private static voID makeEffects(PathEffect[] e,float phase) { e[0] = null; // no effect e[1] = new CornerPathEffect(10); e[2] = new DashPathEffect(new float[] {10,5,5},phase); e[3] = new PathDashPathEffect(makePathDash(),12,phase,PathDashPathEffect.Style.MORPH); e[4] = new ComposePathEffect(e[2],e[1]); e[5] = new ComposePathEffect(e[3],e[1]); } public SampleVIEw(Context context) { super(context); setFocusable(true); setFocusableIntouchMode(true); mPaint = new Paint(Paint.ANTI_AliAS_FLAG); mPaint.setStyle(Paint.Style.stroke); mPaint.setstrokeWIDth(6); mPath = makeFollowPath(); mEffects = new PathEffect[6]; mcolors = new int[] { color.BLACK,color.RED,color.BLUE,color.GREEN,color.magenta,color.BLACK }; } @OverrIDe protected voID onDraw(Canvas canvas) { canvas.drawcolor(color.WHITE); RectF bounds = new RectF(); mPath.computeBounds(bounds,false); canvas.translate(10 - bounds.left,10 - bounds.top); makeEffects(mEffects,mPhase); invalIDate(); for (int i = 0; i < mEffects.length; i++) { mPaint.setPathEffect(mEffects[i]); mPaint.setcolor(mcolors[i]); canvas.drawPath(mPath,mPaint); canvas.translate(0,28); } } @OverrIDe public boolean onKeyDown(int keyCode,KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_DPAD_CENTER: mPath = makeFollowPath(); return true; } return super.onKeyDown(keyCode,event); } private static Path makeFollowPath() { Path p = new Path(); p.moveto(0,0); for (int i = 1; i <= 15; i++) { p.lineto(i*20,(float)Math.random() * 35); } return p; } private static Path makePathDash() { Path p = new Path(); p.moveto(-6,4); p.lineto(6,3); p.lineto(-6,3); p.close(); p.moveto(-6,-4); p.lineto(6,-3); p.lineto(-6,-3); return p; } }}总结
以上是内存溢出为你收集整理的android – 在画布上绘制时自定义路径线条样式全部内容,希望文章能够帮你解决android – 在画布上绘制时自定义路径线条样式所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)