Home > Net >  How to make LinearGradient with list of colors?
How to make LinearGradient with list of colors?

Time:06-14

I am using LinearGradient which supports only 2 colors. And i want to make gradient with list of colors and set it programmatically.

CodePudding user response:

LinearGradient Documentation

You can specify an array of colors and the LinearGradient class will automatically draw them distributed evenly along the gradient line.

Example:

float[] positions = null;
int[] colors = {
    Color.BLACK,
    Color.RED,
    Color.GREEN
};
paint.setShader(new LinearGradient(0f, 0f, (float)bounds.width(), 0f, colors, positions, Shader.TileMode.MIRROR));
  • Related