Problem with transition animation between fragments

3

I'm working on an app that is made up of several fragments and I've decided to put animations between them. Searching, I found that I should use the setCustomAnimations command to get the desired result, but I only get two possible animations: fade-in and fade-out.

Looking at the platform folders I'm using ( android-19 , or Android 4.4.2) I saw that there are other animations that are not available in my SDK are present in the folder ( fragment_close_enter/exit , fragment_fade_enter/exit , fragment_open_enter/exit ).

Why is not my SDK recognizing them? This is the code I am using to create fragment :

FragmentTransaction transFrag = getFragmentManager().beginTransaction();
Fragment login = new LoginFragment();
transFrag.setCustomAnimations(android.R.animator.fade_in,
        android.R.animator.fade_out);
transFrag.addToBackStack(null);
transFrag.replace(R.id.container_login, login);
transFrag.commit();
    
asked by anonymous 11.05.2014 / 06:47

1 answer

5

Why do not you create your own animations using an xml with an objectAnimator?

Seven animations like this:

FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
Fragment login = new LoginFragment();
ft.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_right);
ft.replace(R.id.container_login, login, "login");
ft.commit();

An example of the slide_in_left animation using the objectAnimator:

<?xml version="1.0" encoding="utf-8"?>
<set>
  <objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
    android:propertyName="x" 
    android:valueType="floatType"
    android:valueFrom="-1280"
    android:valueTo="0" 
    android:duration="500"/>
</set>

For the slide_out_right animation, just reverse the values. The two animations (slide_in_left and slide_out_right) are in the res / anim folder

    
11.05.2014 / 14:10