Fragmenttransation Setcustomanimations Not Working
Solution 1:
This works in the current version of the library, but it was definitely broken previously. You can use something like this:
finalFragmentManagerfm= getSupportFragmentManager();
finalFragmentTransactionft= fm.beginTransaction();
ft.setCustomAnimations(R.anim.slide_up, R.anim.slide_down, R.anim.slide_up, R.anim.slide_down)
.add(R.id.fragment_container, newSomeFragment(), FRAGMENT_TAG)
.addToBackStack(FRAGMENT_TAG)
.commit();
where R.anim.slide_up is your in animation and R.anim.slide_down is your out animation. The second pair of params (3 and 4) for setCustomAnimations allow you to specify the pop in/out animations for popping the backstack (e.g., when the user presses back, the fragment will animate away with the animation specified as the fourth param).
Solution 2:
I have found a workaround for this. Override onCreateAnimation(int transit, boolean enter, int nextAnim) in your fragment class then its working fine.
@Overridepublic Animation onCreateAnimation(int transit, boolean enter, int nextAnim) {
return enter ? AnimationUtils.loadAnimation(getActivity(), R.anim.grow_fade_in_center) : AnimationUtils.loadAnimation(getActivity(), R.anim.shrink_fade_out_center);
}
Solution 3:
I am facing the same problem too, here's my situation:
- I want to do some UI change after exit animation. but I found that exit animation didn't work. my UI change codes are in onBackPressed().
my solution is as following:
- move UI change logic in onCreateAnimator(). and then exit animation works.
Solution 4:
Use the below example:
privatefungotoFragment(fragment:Fragment){
parentFragmentManager.commit {
setCustomAnimations(
R.anim.slide_in,
R.anim.fade_out,
R.anim.fade_in,
R.anim.slide_out
)
setReorderingAllowed(true)
replace(R.id.fragment_dashboard_container, fragment)
addToBackStack(null)
}
}
Here is the doc Fragment transactions
Post a Comment for "Fragmenttransation Setcustomanimations Not Working"