Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.RuntimeException: Unknown animation name: objectAnimator

I am getting this error when using

getActivity().getSupportFragmentManager()
                        .beginTransaction()
                        .setCustomAnimations(
                                R.animator.card_flip_right_in, R.animator.card_flip_right_out,
                                R.animator.card_flip_left_in, R.animator.card_flip_left_out)
                        .replace(R.id.content_fragment, new DaysSinceBirthSettingFragment())
                        .addToBackStack(null)
                        .commit();

But when i change it to

getActivity().getFragmentManager()
                        .beginTransaction()
                        .setCustomAnimations(
                                R.animator.card_flip_right_in, R.animator.card_flip_right_out,
                                R.animator.card_flip_left_in, R.animator.card_flip_left_out)
                        .replace(R.id.content_fragment, new DaysSinceBirthSettingFragment())
                        .addToBackStack(null)
                        .commit();

It works perfect. but i need to support older version, so i have to use support-v4, which getSupportFragmentManager() comes from.

I read some article saying that res/animator is not supported by support-v4, so i also tried to move my animation XML files into res/anim folder and reference it by R.anim.card_flip_right_in

But still it didn't work, anyone can tell me what can i do?

like image 368
Scott Zhu Avatar asked Sep 25 '13 15:09

Scott Zhu


2 Answers

Support fragment manager does not support animators (only animations). Exception message says that you have wrong format of animation in your xml resource, probably because you have moved animator to this xml which is wrong (because they have different notation). You need to write it in proper way: http://developer.android.com/guide/topics/graphics/view-animation.html

like image 64
q1p Avatar answered Nov 16 '22 21:11

q1p


if you are using support fragment add below xml files in res

Following will be the content of anim/fragment_slide_left_enter.xml file.

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="@android:integer/config_mediumAnimTime"
        android:fromXDelta="100%p"
        android:interpolator="@android:interpolator/decelerate_quint"
        android:toXDelta="0%p" />

    <alpha
        android:duration="@android:integer/config_mediumAnimTime"
        android:fromAlpha="0.0"
        android:interpolator="@android:interpolator/decelerate_quint"
        android:toAlpha="1.0" />
</set>

following will be the content of anim/fragment_slide_left_exit.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="@android:integer/config_mediumAnimTime"
        android:fromXDelta="0%p"
        android:interpolator="@android:interpolator/decelerate_quint"
        android:toXDelta="-100%p" />

    <alpha
        android:duration="@android:integer/config_mediumAnimTime"
        android:fromAlpha="1.0"
        android:interpolator="@android:interpolator/decelerate_quint"
        android:toAlpha="0.0" />
</set>

Following code will be the content of anim/fragment_slide_right_enter.xml file

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="@android:integer/config_mediumAnimTime"
        android:fromXDelta="-100%p"
        android:interpolator="@android:interpolator/decelerate_quint"
        android:toXDelta="0%p" />

    <alpha
        android:duration="@android:integer/config_mediumAnimTime"
        android:fromAlpha="0.0"
        android:interpolator="@android:interpolator/decelerate_quint"
        android:toAlpha="1.0" />
</set>

following code will be the content of anim/fragment_slide_right_exit.xml file

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">

    <translate
        android:duration="@android:integer/config_mediumAnimTime"
        android:fromXDelta="0%p"
        android:interpolator="@android:interpolator/decelerate_quint"
        android:toXDelta="100%p" />

    <alpha
        android:duration="@android:integer/config_mediumAnimTime"
        android:fromAlpha="1.0"
        android:interpolator="@android:interpolator/decelerate_quint"
        android:toAlpha="0.0" />
</set>

finally add this line in your fragment transition code

ft.setCustomAnimations(R.anim.fragment_slide_left_enter,
                        R.anim.fragment_slide_left_exit,
                        R.anim.fragment_slide_right_enter,
                        R.anim.fragment_slide_right_exit)
like image 20
Jinu Avatar answered Nov 16 '22 21:11

Jinu