2

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);
Rodia
  • 1,407
  • 8
  • 22
  • 29
Dmitry Lyalin
  • 341
  • 6
  • 15

1 Answers1

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.

Attila Tanyi
  • 4,904
  • 5
  • 27
  • 34
  • Thank You! I'm a newBie so it was rather stupid question( – Dmitry Lyalin Jan 28 '16 at 09:16
  • Glad if I could help, I don't think there is such a thing as a stupid question :) – Attila Tanyi Jan 28 '16 at 15:18
  • I have more questions(( Can i get width and height of the screen but not in OnDraw()? Im trying to create all Shaders (Odjects) before OnDraw(), but it have some dependence from width and height of the screen .. – Dmitry Lyalin Jan 29 '16 at 08:20
  • Just search around here on Stack Overflow, there are plenty of Android questions. This one might help with getting the width and height: http://stackoverflow.com/a/6652621/3160869 Also, if you cannot find what you're looking for, you can post a new (separate) question. Stack Overflow is all about making it easy for other people to find your questions later. – Attila Tanyi Jan 29 '16 at 14:24