Reputation: 21
I've been searching all around the internet and every time I came up with the same result , I want to set a custom Animation to my Fragments , check the following code out : FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.setCustomAnimations(R.anim.slide_in_right);
SpeedMatchFragment speedMatchFragment = new SpeedMatchFragment();
fragmentTransaction.replace(R.id.fragment_container,speedMatchFragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
but here fragmentTransaction.setCustomAnimations(R.anim.slide_in_right); I'm getting cannot resolve error ! notice that I've already made the anim folder the xml ... and all stuff need to be done ! here is the xml code :
<set>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="-100%"
android:toXDelta="0"
android:interpolator="@android:anim/decelerate_interpolator"
android:duration="@android:integer/config_mediumAnimTime"/>
Upvotes: 0
Views: 35
Reputation: 1796
To my understanding you have to set the enter and exit animation, then the error will go like magic....
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.setCustomAnimations(R.anim.pop_enter, R.anim.pop_exit);
SpeedMatchFragment speedMatchFragment = new SpeedMatchFragment();
fragmentTransaction.replace(R.id.fragment_container,speedMatchFragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
Upvotes: 1