How to fill different color on same area of imageview (Color over another Color on same area of imageview)?

徘徊边缘 提交于 2019-12-06 06:46:55

The problem you have is your drawing all your Paths with a PorterDuff.Mode. What you really want to do is to draw all your paths without any PorterDuff.Mode and then take that final render and apply it to your A shape with a PorterDuff.Mode. Given more time I should be able to write an example for you. You also have many other issues with your code.

Solution: https://github.com/slightfoot/android-painter-example

If you want multiple layers in your image having different color at each layer you can use A LayerDrawable . LayerDrawable allows you to create a Drawable object with different layers. You can position the layers according to your needs.

Example:

Drawable largeIcon = getResources().getDrawable(R.drawable.app_icon);

ShapeDrawable bg = new ShapeDrawable();
bg.getPaint().setColor(Color.RED);

Drawable[] layers = {bg, largeIcon};

LayerDrawable layerDrawable = new LayerDrawable(layers);
layerDrawable.setLayerInset(0, 0, 0, 0, 0);
layerDrawable.setLayerInset(1, 35, 35, 35, 35);  // relative positioning of next layer 

return layerDrawable

On ACTION_UP you do something strange, here is your code:

        path.lineTo(eventX, eventY);
        canvas.drawPath(path, paint);
        paths.add(path);
        path.reset();

At the end the path is clear. Next time you get there you add a lineTo, and draw it, which will be an empty path. The you add the path to paths, and clear path. This is the only canvas drawing code I see, so I don't even understand where your problem is

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!