setGradientCenter (gradientDrawable.setGradientCenter) is not working in GradientDrawable

505 Views Asked by At

I am creating GradientDrawable and it's working fine. But now I need to give centerX and centerY position of GradientDrawable and I am giving with below code

GradientDrawable gradientDrawable = new GradientDrawable();
gradientDrawable.setColors(new int[]{StartColor, EndColor});
gradientDrawable.setGradientType(GradientDrawable.LINEAR_GRADIENT);
gradientDrawable.setGradientCenter(CenterXPosition, CenterYPosition); // CenterYPosition = 0.5 and CenterXPosition = (0-100) values I am giving
viewGradientLayout.setBackground(gradientDrawable);

but It is not working. setGradientCenter is not changing anything in my drawable.

this is my Imageview in which I am showing my drawable.

enter image description here

Note:-

  1. I tried giving CenterXPosition values between 0.0 to 1
  2. I tried giving

    gradientDrawable.setShape(GradientDrawable.RECTANGLE);
    

gradient center stays at center position... without any movement.. What could be wrong? Thanks for your answers.

any other solution to show like it also accepted.

0

There are 0 best solutions below