How to force android view to redraw it's background-drawable? / probably an animation is blocking it to work properly

StackOverflow https://stackoverflow.com/questions/4748336

Question

Is there a way to force an android view to redraw it's background? I have set a drawable shape with a gradient as background which works fine but after changing the view's height you can see those ugly gradient steps.

What can I do? I tried view.invalidate() and view.refreshDrawableState() without any visible difference.

Thank you!

//EDIT: Here are some more details and my code: After your answers I think the banding is a result of my probably bad code. Here is what I'm doing:

  1. Scaling a view
  2. setting its new width and height because the scaled view does not accept user input in other areas then the "old" one (see android weird (at least for me) behaviour of control after scaling / doesn't accept input in it's whole area )
  3. trying to set the background again (which contains a gradient and a rectangle with rounded corners)

Here is my code:

public void onAnimationEnd(Animation animation)
{
    MyView view = (MyView) ((ExtendedScaleAnimation) animation).getView();
    view.getLayoutParams().width = toWidth;
    view.getLayoutParams().height = toHeight;
    view.clearAnimation();
    view.requestLayout();
    view.refreshBackground(); // background will be changed
}

On the device you can see that the background drawable is changed but there is a flickering which seems to me like the backround change is applied before the animation is over. Programatically it should be over! Or am I wrong?

Thank you again!

Was it helpful?

Solution

Can you try after resize: v.setBackgroundResource(null); v.setBackgroundResource(...my drawable...);

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top