Android Canvas Gradient

1

Example

I try to draw this on Android canvas, and I have questions...

  1. Why all shaders results have only white and black? There are no colors...

  2. How to set color for more than two points (x,y)?

  3. Where can I find examples that will show simple combinations of use?

Code:

Shader1 = new LinearGradient(0, 0, 0,BarHeight,0xff696969 ,0xffffffff,   Shader.TileMode.CLAMP);
Shader2 = new LinearGradient(BarHeight/2, BarHeight/2, 0,34,0xf0696969 ,0xfff34f5f, Shader.TileMode.CLAMP);
ComposeShader mShader = new ComposeShader(Shader2, Shader1,  PorterDuff.Mode.MULTIPLY);
GraundPaint.setShader(mShader);
canvas.drawRoundRect(rectf, 0, 0, GraundPaint);
android
canvas
gradient
asked on Stack Overflow Jan 27, 2016 by Dmitry Lyalin • edited Jun 18, 2018 by Rodia

1 Answer

0

You can set more than 2 points by using this constructor of LinearGradient, which takes an array of colors and the corresponding array of positions (between 0 and 1).

For a simple example using LinearGradient, you may look here.

answered on Stack Overflow Jan 27, 2016 by Attila Tanyi

User contributions licensed under CC BY-SA 3.0