android shader效果概览


LinearGradient

1
2
3
4
float[] positions = {0.0f, 0.5f, 1.0f};
int[] colors = {Color.RED, Color.GREEN, Color.MAGENTA};
Shader.TileMode tileMode = Shader.TileMode.MIRROR;
Shader linearGradient = new LinearGradient(x0, y0, x1, y1, colors, positions, tileMode);

RadialGradient

1
2
3
4
float[] positions = {0.0f, 0.5f, 1.0f};
int[] colors = {Color.RED, Color.GREEN, Color.MAGENTA};
Shader.TileMode tileMode = Shader.TileMode.MIRROR;
Shader radialGradient = new RadialGradient(centerX, centerY, radius, colors, positions, tileMode);

SweepGradient

1
2
3
float[] positions = {0.0f, 0.5f, 1.0f};
int[] colors = {Color.RED, Color.GREEN, Color.MAGENTA};
Shader sweepGradient = new SweepGradient(centerX, centerY, colors, positions);

BitmapShader

1
BitmapShader bitmapShader = new BitmapShader(bitmap, tileX, tileY);

ComposeShader

1
ComposeShader composeShader = new ComposeShader(linearGradient, bitmapShader, PorterDuff.Mode.ADD);