Fragment : Unknown animation name objectanimator
Asked Answered
S

3

30

I'm trying to do a flipping card animation between two fragment like in --> Displaying Card Flip Animations by using:

private void switchFragment(Fragment fragment) {
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager
                .beginTransaction();

        if ((fragment != null) && !(fragment.equals(currentFragment))) {

            if (transactionByMenu) {
                fragmentTransaction.setCustomAnimations(android.R.anim.fade_in,
                        android.R.anim.fade_out);
            } else {
                fragmentTransaction.setCustomAnimations(
                        R.animator.card_flip_right_in,
                        R.animator.card_flip_right_out);
            }

            Fragment nextFragment = fragment;
            fragmentTransaction.hide(currentFragment);
            fragmentTransaction.show(nextFragment);

            currentFragment = nextFragment;
        }
        fragmentTransaction.commit();
    }

The transaction in if(transactionByMenu){...} works but not in else{...}

I'd check my libs and stuff and i'm currently target higher than api 11 but I still have this error message:

05-22 11:32:34.706: E/AndroidRuntime(6801): FATAL EXCEPTION: main
05-22 11:32:34.706: E/AndroidRuntime(6801): java.lang.RuntimeException: Unknown animation name: objectAnimator
05-22 11:32:34.706: E/AndroidRuntime(6801):     at android.view.animation.AnimationUtils.createAnimationFromXml(AnimationUtils.java:124)
05-22 11:32:34.706: E/AndroidRuntime(6801):     at android.view.animation.AnimationUtils.createAnimationFromXml(AnimationUtils.java:114)
05-22 11:32:34.706: E/AndroidRuntime(6801):     at android.view.animation.AnimationUtils.createAnimationFromXml(AnimationUtils.java:91)
05-22 11:32:34.706: E/AndroidRuntime(6801):     at android.view.animation.AnimationUtils.loadAnimation(AnimationUtils.java:72)
05-22 11:32:34.706: E/AndroidRuntime(6801):     at android.support.v4.app.FragmentManagerImpl.loadAnimation(FragmentManager.java:710)
05-22 11:32:34.706: E/AndroidRuntime(6801):     at android.support.v4.app.FragmentManagerImpl.hideFragment(FragmentManager.java:1187)
05-22 11:32:34.706: E/AndroidRuntime(6801):     at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:610)
05-22 11:32:34.706: E/AndroidRuntime(6801):     at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1431)
05-22 11:32:34.706: E/AndroidRuntime(6801):     at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:420)
05-22 11:32:34.706: E/AndroidRuntime(6801):     at android.os.Handler.handleCallback(Handler.java:725)
05-22 11:32:34.706: E/AndroidRuntime(6801):     at android.os.Handler.dispatchMessage(Handler.java:92)
05-22 11:32:34.706: E/AndroidRuntime(6801):     at android.os.Looper.loop(Looper.java:137)
05-22 11:32:34.706: E/AndroidRuntime(6801):     at android.app.ActivityThread.main(ActivityThread.java:5041)
05-22 11:32:34.706: E/AndroidRuntime(6801):     at java.lang.reflect.Method.invokeNative(Native Method)
05-22 11:32:34.706: E/AndroidRuntime(6801):     at java.lang.reflect.Method.invoke(Method.java:511)
05-22 11:32:34.706: E/AndroidRuntime(6801):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-22 11:32:34.706: E/AndroidRuntime(6801):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-22 11:32:34.706: E/AndroidRuntime(6801):     at dalvik.system.NativeStart.main(Native Method)

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="package.stage.stackoverflow"
    android:versionCode="3"
    android:versionName="2.0.1" >

    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="17" />

    <permission
        android:name="package.stage.stackoverflow.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="package.stage.stackoverflow.permission.MAPS_RECEIVE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/SampleTheme" >
        <uses-library android:name="com.google.android.maps" />

        <activity
            android:name="package.stage.stackoverflow.MyFragmentActivity"
            android:label="@string/app_name"
            android:launchMode="singleTop"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="my Key" />
    </application>

</manifest>

It's been two day I'am stuck with this, thank you in advance.

Supersedure answered 22/5, 2013 at 9:59 Comment(6)
can you please try custom animation instead of android.R.anim.fade_in and fade_outLoment
Oh sorry i edited my it didn't Copy/paste the right instruction. Actually it is fragmentTransaction.setCustomAnimations( R.animator.card_flip_left_in, R.animator.card_flip_left_out);Supersedure
can you add full code for fragment transaction ?Loment
Edit done : The transaction in if(transactionByMenu){...} works but not in else{...}Supersedure
I think issue is on your animator.card_flip_right_in, can you please code of that too, Generally we add animations in anim folder and access them using R.anim.animation_nameLoment
I used the same XML as in the --> Displaying Card Flip AnimationsSupersedure
F
51

I believe you are trying to use objectAnimator in support fragments library, but it was added in Android Api level 11.

Fadge answered 24/5, 2013 at 11:52 Comment(8)
then you should use getFragmentManager instead of getSupportFragmentManager.Fadge
Ok so i can't use it with support fragment or Sherlock on 11 that's it ?Supersedure
If your app target minSDKVersion - 11, then there is no need to use getSupportFragmentManager, because getFragmentManager() can be used and then you can also use objectAnimator.Fadge
and what if i want to use it with Support Library ?Supersedure
then you can not use ObjectAnimator, so you'll have to create the flip animation in a different way, simple as that :)Fadge
Thank you very for this answer, I figured it in another way : THERESupersedure
@GlennSonna Can you let us know what is the other way which worked for you?Dissuasion
The Tutorial you posted under "THERE" isn't about the problem. Until yet there is no solution for this question!Hoang
L
17

If you declared your object animation in an xml file, be sure to put it into the animator folder and not the anim folder to tell android to use the new animation framework.

Here from the documentation :

To distinguish animation files that use the new property animation APIs from those that use the legacy view animation framework, starting with Android 3.1, you should save the XML files for property animations in the res/animator/ directory (instead of res/anim/). Using the animator directory name is optional, but necessary if you want to use the layout editor tools in the Eclipse ADT plugin (ADT 11.0.0+), because ADT only searches the res/animator/ directory for property animation resources.

Lorinalorinda answered 14/8, 2014 at 12:29 Comment(0)
L
3
FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
                FragmentTransaction fragmentTransaction = fragmentManager
                        .beginTransaction();
                fragmentTransaction.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left,R.anim.slide_in_left, R.anim.slide_out_right);
                ProductOverview commentFragment = new ProductOverview();
                commentFragment.setArguments(b);
                fragmentTransaction.replace(R.id.product_container, commentFragment);
                fragmentTransaction.addToBackStack(null);
                fragmentTransaction.commit();
Loment answered 22/5, 2013 at 11:16 Comment(2)
What is commentFragment.setArguments(b); ? I can't use the replace I need to keep all of my Fragments's states, that's why I rather use show/hide.Supersedure
Using setArguments you can attach a Bundle and then in your fragment you can call getArguments to retrieve any values you attach to the bundle. This is a useful way of passing certain types of information into a fragment when creating a new instance.Flier

© 2022 - 2024 — McMap. All rights reserved.