I want to create a CircleView with gradient from bottom -> left -> top -> right.
So I using canvas with SweepGradient
like this
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint paint = new Paint();
int[] colors = {Color.GREEN, Color.RED};
float[] positions = {0, 1};
SweepGradient gradient = new SweepGradient(100, 100, colors, positions);
paint.setShader(gradient);
canvas.drawCircle(100, 100, 100, paint);
}
But the default order of this is right -> bottom -> left -> top but I want bottom -> left -> top -> right I have tried change the positions to
float[] positions = {0.25f, 1.25f};
but it only works in Preview
of AndroidStudio, when I run in real device, it displays the result as same as positions = {0, 1}
How can I make SweepGradient
gradient from bottom -> left -> top -> right
like this
--- UPDATE ---
We can use setLocalMatrix
for SweepGradient
like this for rotate the gradient
Matrix matrix = new Matrix();
matrix.setRotate(90, 100, 100);
gradient.setLocalMatrix(matrix);