Reputation: 1932
I am having some trouble trying to set custom animation to my fragment transaction. I know there are several treads on this and I have tried all their soluction and I still cant get this to work. Here are the animation xml files:
slide.down.xml(for exit)
<set xmlns:android="”http://schemas.android.com/apk/res/android”"
android:shareInterpolator="false" >
<translate
android:duration="700"
android:fromXDelta="0%"
android:fromYDelta="-100%"
android:toXDelta="0%"
android:toYDelta="0%" />
slide_up.xml(for entering)
<set xmlns:android="”http://schemas.android.com/apk/res/android”"
android:shareInterpolator="false" >
<translate
android:duration="700"
android:fromXDelta="0%"
android:fromYDelta="0%"
android:toXDelta="0%"
android:toYDelta="-100%"/>
and my fragment transaction code:
getFragmentManager().beginTransaction()
.setCustomAnimations(R.anim.slide_up , R.anim.slide_down,R.anim.slide_up , R.anim.slide_down)
.replace(R.id.container, list)
.addToBackStack(null)
.commitAllowingStateLoss();
All the solutions form other similar threads I have tried:
setCustomAnimations
is before replace
android:hardwareAccelerated
to true in the Manifest.I seem to be messing something very obvious and important but I cant figure out what that is.
My question: Why doesn't my costume animation work and how do I get it to work ?
Upvotes: 1
Views: 1599
Reputation: 25584
So, there are two types of animations in Android. View Animation (Animation) and Property Animation (Animator). Your animations are the former, while FragmentTransaction.setCustomAnimations
expects the latter. You have 2 options to fix this:
android.support.v4.app.Fragment
getSupportFragmentManager()
to create the FragmentTransaction
ViewGroup
(explained here)objectAnimator
(XML)The first option is definitely the easier one, especially since you're going for a on/off screen translation, and it expects the types of animations that you've already defined.
To learn more about the difference between the two animations, see here.
Upvotes: 4