Android View.bringToFront () causes flickering

I have several views in FrameLayout. There is a transition that I wrote, where each view has a custom animation class. During this transition, I need to bring the representation at the bottom of the z-order to the front. I am doing this with:

public static void putBackAtFront(ViewGroup v) { v.getChildAt(0).bringToFront(); refreshEverything(v); } 

This is called from applyTransformation () of my custom animation.

i.e.

 public class PivotAnimation extends Animation { private View view; ... @Override protected void applyTransformation(float interpolatedTime, Transformation t) { ... if(interpolatedTime >= 1.f && isAtBack(view)) { putBackAtFront(view); } ... } ... } 

refreshEverything () calls invalidate () and requestLayout () for the parent FrameLayout and all its children.

Everything works fine, except that when you call putBackAtFront (), the view that is now at the bottom disappears for one frame before instantly reappearing, which leads to a noticeable flicker. I also tried without calling refreshEverything (), it doesn't matter.

I aimed at API level 7.

+6
source share
2 answers

applyTransformation () is called several times during the animation, so you should do the animation based on Time interpolation, when its 1.0, the animation is at the end, so you have to bring your output to the foreground.

So, in my opinion, this flicker occurs when in some of these calls to your method getChildAt (0) gets a different view than the one you need, and flicker appears.

+1
source

I think this should be one of three things:

If you are building API 3.0+, hardware acceleration may be enabled. It is also included by default in 4.0. You can try using

  setLayerType(LAYER_TYPE_SOFTWARE, null); 

to disable HW acceleration in this layout / view / window.

Also, you may not need to call requestLayout (), if all views are children of relativelayout, changing the z-index should not concern this.

The call of invalidity is almost unnecessary. Have you tried to make the look attractive and just call requestFocus () instead of bringing ToFront () at all? The bringToFront () function obviously removes the view from its parent and reattaches it. This can easily lead to invalidation between steps, since I don't think something pauses the drawing while this happens.

0
source

Source: https://habr.com/ru/post/911591/


All Articles