Skip to content

Instantly share code, notes, and snippets.

@arnaud33200
Created March 5, 2019 15:21
Show Gist options
  • Save arnaud33200/cc38f59a1153f711cd0c09d67e908fd1 to your computer and use it in GitHub Desktop.
Save arnaud33200/cc38f59a1153f711cd0c09d67e908fd1 to your computer and use it in GitHub Desktop.
public static PaintDrawable createTopBottomLinearGradientPaintDrawable(TwoColorGradient twoColorGradient, final float center) {
final int[] colors =
new int[]{twoColorGradient.getGradientStartColor(), twoColorGradient.getGradientEndColor()};
ShaderFactory sf = new ShaderFactory() {
@Override
public Shader resize(int width, int height) {
float[] positions = new float[]{0.0f, center};
return new LinearGradient(0, 0, 0, width, colors, positions, TileMode.CLAMP);
}
};
PaintDrawable paintDrawable = new PaintDrawable();
paintDrawable.setShape(new RectShape());
paintDrawable.setShaderFactory(sf);
return paintDrawable;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment