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

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

问题描述

在$ C $下画一个箭头用的风格:填写的是如下:

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

和我得到的输出是这样的:

现在我想要做的是设置样式为渐变(Style.gradient不是present的机器人...),以获得类似于图像的方向如下:

我怎么办呢?我尝试添加的风格style.xml,但无法添加渐变那里,因为它接受项目作为参数。<​​/ P>

解决方案

使用code以下。

  paint.setShader(新的LinearGradient(0,0,0,getHeight()都会,Color.BLACK,Color.WHITE,Shader.TileMode.MIRROR));
    canvas.drawPath(arrowPath,油漆);
 

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 :

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 :

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..

解决方案

use the code below..

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

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

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