I am trying to use animation while replacing fragments
(with replace()
of fragment transaction
). I set animtaions with setCustomAnimations()
.
My animation
is trying to overlap an old fragment
with a new one moving from right. But the problem is: I can see views from old fragment
even when it is already overlapped by the new one. And old views
dissapear only when the animation is done. Also, when a new fragment
is a complicated one (listviews
, etc...), I can see some artefacts and flickering while overlapping.
This is terrible, how can i avoid that?
My code for enter animation
:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:ordering="together">
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:propertyName="x"
android:valueType="floatType"
android:valueTo="0"
android:valueFrom="720"
android:duration="250"
android:zAdjustment="top"/>
</set>
UPDATE: about artefacts - it's not them. It was just the consequences of bad overlay. I watched animation slowly. So the problem is: the old fragment stays on TOP. It completely overlaps the new one while animating.
Your problem happens because you are using same animator file in enter and exit animation, you have to set exit animation for old fragment different from enter one, like to another side
transaction.setCustomAnimations(<enterAnimationResId>, <exitAnimationResId>);
where enterAnimationResId
is a xml file containing animation to be applied on entering fragment, and exitAnimationResId
is a xml file containing animation to be applied on closing the existing fragment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With