如何设置渐变样式来绘制对象? [英] How to set gradient style to paint object?

查看:24
本文介绍了如何设置渐变样式来绘制对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用样式:填充绘制箭头的代码如下:

The code for drawing an arrow with Style: Fill is given below:

paint.setColor(Color.parseColor("#bdc0dc"));
paint.setStyle(Style.FILL);
canvas.drawPath(arrowPath, paint);
paint.setColor(Color.BLACK);
paint.setStyle(Style.STROKE);
paint.setStrokeWidth(2);
canvas.drawPath(arrowPath, paint);

我得到的输出是这样的:

And the output I obtain is this :

现在我想要做的是将样式设置为 Gradient(Style.gradient not present in android...) 以获得类似于下面给出的图像的箭头:

Now what I want do is set style to Gradient(Style.gradient not present in android...) to obtain the arrow similar to the image given below :

我该怎么做?我尝试在 style.xml 中添加样式,但无法在那里添加渐变,因为它接受项目作为参数..

How do i do it ? I tried adding style in style.xml but was unable to add gradient there as it accepts item as parameter..

推荐答案

使用下面的代码..

paint.setShader(new LinearGradient(0, 0, 0, getHeight(), Color.BLACK, Color.WHITE, Shader.TileMode.MIRROR));
    canvas.drawPath(arrowPath, paint);

这篇关于如何设置渐变样式来绘制对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆