Created
October 4, 2018 08:23
-
-
Save zerobranch/8c2f4f1dc8ae8283cba2474d13ed9428 to your computer and use it in GitHub Desktop.
When animating, the next fragment will be ABOVE the previous one. Copy xml resources to res/animator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class BaseMainFragment extends Fragment { | |
@Override | |
public Animation onCreateAnimation(int transit, final boolean enter, int nextAnim) { | |
if (nextAnim == R.animator.next_fragment_anim) { | |
Animation nextAnimation = AnimationUtils.loadAnimation(getContext(), nextAnim); | |
nextAnimation.setAnimationListener(new Animation.AnimationListener() { | |
private float startZ = 0f; | |
@Override | |
public void onAnimationStart(Animation animation) { | |
if (getView() != null) { | |
startZ = ViewCompat.getTranslationZ(getView()); | |
ViewCompat.setTranslationZ(getView(), 1f); | |
} | |
} | |
@Override | |
public void onAnimationEnd(Animation animation) { | |
if (getView() != null) { | |
getView().postDelayed(() -> { | |
if (getView() != null) { | |
ViewCompat.setTranslationZ(getView(), startZ); | |
} | |
}, 100); | |
} | |
} | |
@Override | |
public void onAnimationRepeat(Animation animation) { | |
} | |
}); | |
return nextAnimation; | |
} else { | |
return null; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<set xmlns:android="http://schemas.android.com/apk/res/android" | |
android:interpolator="@android:anim/linear_interpolator"> | |
<translate | |
android:duration="150" | |
android:fromXDelta="0%" | |
android:toXDelta="-10%"/> | |
</set> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<set xmlns:android="http://schemas.android.com/apk/res/android" | |
android:interpolator="@android:anim/linear_interpolator"> | |
<translate | |
android:duration="150" | |
android:fromXDelta="0%" | |
android:toXDelta="100%"/> | |
</set> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<set xmlns:android="http://schemas.android.com/apk/res/android" | |
android:interpolator="@android:anim/linear_interpolator"> | |
<translate | |
android:duration="150" | |
android:fromXDelta="100%" | |
android:toXDelta="0%"/> | |
</set> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<set xmlns:android="http://schemas.android.com/apk/res/android" | |
android:interpolator="@android:anim/linear_interpolator"> | |
<translate | |
android:duration="150" | |
android:fromXDelta="-10%" | |
android:toXDelta="0%"/> | |
</set> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment