java - 自定义笔触以具有边框和填充
问题描述
如何使用填充颜色和(不同颜色)边框绘制笔触?
例如我想要这样的东西:
我尝试创建 2 种油漆 - 一种具有 Stroke 风格,一种具有 Fill 风格,但调用
strokePaint = new Paint();
strokePaint.setStyle(Paint.Style.STROKE);
strokePaint.setColor(Color.parseColor("#A3A3A3"));
fillPaint = new Paint();
fillPaint.setStyle(Paint.Style.FILL);
fillPaint.setColor(Color.WHITE);
canvas.drawPath(totalPath, strokePaint);
canvas.drawPath(totalPath, fillPaint);
不会产生预期的效果,而且看起来很糟糕。
甚至可能吗?
解决方案
弄清楚了。诀窍是绘制两次,一次作为厚 1-2 像素的背景层,然后是前景层。
IE :
strokePaintBackground = new Paint(Paint.ANTI_ALIAS_FLAG);
strokePaintBackground.setStyle(Paint.Style.STROKE);
strokePaintBackground.setColor(Color.BLACK);
strokePaintBackground.setStrokeWidth(8);
strokePaintBackground.setPathEffect(new DashPathEffect(new float[]{30, 15}, 0));
strokePaintBackground.setStrokeCap(Paint.Cap.ROUND);
strokePaintBackground.setStrokeJoin(Paint.Join.ROUND);
strokePaintForground = new Paint(Paint.ANTI_ALIAS_FLAG);
strokePaintForground.setStyle(Paint.Style.STROKE);
strokePaintForground.setColor(Color.WHITE);
strokePaintForground.setStrokeWidth(6);
strokePaintForground.setPathEffect(new DashPathEffect(new float[]{30, 15}, 0));
strokePaintForground.setStrokeCap(Paint.Cap.ROUND);
strokePaintForground.setStrokeJoin(Paint.Join.ROUND);
canvas.drawPath(totalPath, strokePaintBackground);
canvas.drawPath(totalPath, strokePaintForground);
推荐阅读
- angular - 分组和减少从ngrx状态树接收的自定义可观察数组
- javascript - 如何使用 nodejs 在服务器上接收与客户端发布数据格式相同的发布数据?
- haskell - 如何在实例函数中专门化参数/数据类型?(哈斯克尔)
- c# - DotVVM - 在 GridView 中为行着色的可能性是什么?
- reactjs - 反应路由器中未定义的反应上下文值
- hyperledger-fabric - 如何使用 raft 在正在运行的超级账本结构网络中添加新的订购者?
- mysql - MySQL SELECT 不适用于包含换行符的文本
- r - 如何预测R中数据框的下一列
- c++ - 当鼠标左键按下时,如何让我的自动点击器不断点击?
- python - 使用 Keras 进行迁移学习:输入形状不匹配