I answer to myself, JFTR:
Use GradientDrawable instead of LinearGradient, so you can move the same
gradient object to different places just assigning different bounds.
Best regards,
El miércoles, 17 de octubre de 2012 17:52:42 UTC+2, Fran escribió:
>
> Hi there,
>
> I draw a grid on a surface, and each cell of the grid is filled with a
> gradient, so what I do is to create a LinearGradient for each cell, then
> set as a shader for a Paint, and finally create a Rect using that Paint.
>
> Something in the way of:
>
> Paint cellPaint = new Paint();
> ...
> for (i=0; i<cell.length; i++) {
> LinearGradient gradient = new LinearGradient(cell[i].left,
> cell[i].top, 80, 80, Color.BLACK, Color.WHITE, Shader.TileMode.CLAMP);
> cellPaint.setShader(cellGradient);
> canvas.drawRect(cell[i].left, cell[i].top, cell[i].left+79,
> cell[i].top+79, cellPaint);
> }
>
>
> The problem is that I need to create a lot of LinearGradient objects,
> one for each cell, even when they use the same colors, size, etc. and
> just changes the coordinates because each one is drawn on a different
> place.
>
> But LinearGradient constructor seems to use "absolute" coordinates, I
> mean relatives to the whole screen, so a LinearGradient created on x and
> y coordinates, cannot be reused on x2 and y2 (where x2 and y2 are
> different from x and y, of course).
>
> Does someone knows a more or less straight forward manner to solve this
> problem creating just one LinearGradient and then "moving" it to
> different places as needed?
>
> Best regards,
>
>
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en