Search code examples
androidanimationtween

How to create an animation in front of a 3rd party linear layout


I have 5 linear layouts wrapped up in one linear layout, inside a relative layout. I am using a translation animation to move an image button within one linear layout. If I try and move it from from outside the linear layout (in this case a point in another linear layout) into the linear layout it resides in it seems to be behind the other linear layout, ie not visible, and only appears when it crosses into the linear layout it resides within. Can I have it somehow over the other linear layouts? Here is my code.

<translate
    android:duration="2000"
    android:fromXDelta="-40%p"
    android:fromYDelta="100%p"
    android:toXDelta="0%p"
    android:toYDelta="10%p"
    android:zAdjustment="top" />
</set>

Would a frame layout solve this issue? If so, how do I ensure the image in the frame layout appears in front of the linear layouts?


Solution

  • Animate that View on the DecorView. First add it to the decorView and then call translate animation. Remove that view from decorview when animation ends.

    findViewById(R.id.main).addView(viewToAnimate);
    
    viewToAnimate.setAnimationListener(new AnimationListener() {
    
        onAnimationEnd(..) {
            findViewById(R.id.main).removeView(viewToAnimate);
        }
    }
    viewToAnimate.startAnimation();
    

    Code is not exactly what it will be (typed from memory), but should be something like this..