tags:

views:

36

answers:

1

Hello, I have a line drawn vertically, let's say it has 100 pixels. I want to make this line half lenght white, half lenght red. Can I achieve this with a gradient ?

I tried stuff like

linePaint.setShader(
new LinearGradient(x,y, x1, y2, 
new int[] { Color.WHITE, Color.RED},
null,
Shader.TileMode.MIRROR));

canvas.drawLine(x,y,x1,y1,linePaint);

In .NET is very simple to do this with a gradient but in Android I'm stuck. Any help is really appreciated. Thank you.

A: 

The simplest solution should be:

set color white;
canvas.drawLine(x,y,x1,y1/2,linePaint);
set color black;
canvas.drawLine(x,y1/2,x1,y1,linePaint);
Drakosha
thank you for your help.
Alin