0

I am drawing rectangles in Android using the graphics canvas, color, and paint classes. If I have the rectangles stored in an array with a color for each, how would I have the colors gradient from one end to the other? I've been attempting to modify the rgb values using Color.red(colorInt) etc. but I'm getting some strange results.

Edit: Each rectangle itself does not have a gradient. I need each to be a solid color. I've tried multiplying each color component by a weight based on where in the array a rectangle is but it's ineffective.

Here is some of the code I tried.

if(lt != null && rt != null)
{
    int r = (int) ((Color.red(lt.getColor()) * (1.0 - weight)) - (Color.red(rt.getColor()) * weight));
    int g = (int) ((Color.green(lt.getColor()) * (1.0 - weight)) - (Color.green(rt.getColor()) * weight));
    int b = (int) ((Color.blue(lt.getColor()) * (1.0 - weight)) - (Color.blue(rt.getColor()) * weight));

    color = Color.argb(ALPHA, r, g, b);
}

1 Answers1

0

This may not be an exact answer to your question, but might help you to set the gradients to one view:

View yourView = findViewById(R.id.mainlayout);

GradientDrawable gd = new GradientDrawable(
        GradientDrawable.Orientation.TOP_BOTTOM,
        new int[] {0xFF616261,0xFF131313});
gd.setCornerRadius(0f);

yourView .setBackgroundDrawable(gd);

For more info on GradientDrawable.

Community
  • 1
  • 1
amalBit
  • 12,041
  • 6
  • 77
  • 94
  • I don't want each rectangle to have a gradient, but the color of each box to gradient between rectangles in an array. I appreciate you trying to help – CourtJester5 Nov 15 '13 at 10:08