Android 片段:未知动画名称objectanimator

Android 片段:未知动画名称objectanimator,android,animation,android-fragments,objectanimator,Android,Animation,Android Fragments,Objectanimator,我正在尝试使用以下方法在两个片段(如-->中)之间制作翻转卡片动画: private void switchFragment(Fragment fragment) { FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager .beginTransac

我正在尝试使用以下方法在两个片段(如-->中)之间制作翻转卡片动画:

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();
    }
if(transactionByMenu){…}
中的事务在
else{…}

我会检查我的LIB和其他东西,我目前的目标高于api 11,但我仍然有以下错误消息:

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>


已经两天了,我一直在坚持这一点,提前谢谢你。

我相信你正在尝试在支持片段库中使用objectAnimator,但它是在Android Api 11级中添加的。

如果你在xml文件中声明了你的对象动画,确保将其放入animator文件夹,而不是anim文件夹,以告知android使用新的动画框架

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();
以下为:

要区分使用新属性动画API的动画文件与使用旧视图动画框架的动画文件,从Android 3.1开始,您应该将属性动画的XML文件保存在res/animator/目录中(而不是res/anim/)。使用animator目录名是可选的,但如果您想使用Eclipse ADT插件(ADT 11.0.0+)中的布局编辑器工具,则必须使用该名称,因为ADT仅在res/animator/目录中搜索属性动画资源


请尝试自定义动画,而不是android.R.anim.fade\u in和fade\u out哦,对不起,我编辑了我的动画,但没有复制/粘贴正确的说明。实际上是
fragmentTransaction.setCustomAnimations(R.animator.card\u flip\u left\u in,R.animator.card\u flip\u left\u out)你能为片段事务添加完整代码吗?编辑完成:如果(transactionByMenu){…}
中的事务正常,但在
中{…}
我想问题出在你的动画师身上。卡片翻转过来,请你也编码一下,好吗,通常,我们在anim文件夹中添加动画,并使用R.anim.animation_name访问它们
commentFragment.setArguments(b)?我不能使用replace,我需要保留所有片段的状态,这就是为什么我宁愿使用show/hide。使用setArguments,您可以附加一个Bundle,然后在片段中调用getArguments来检索附加到Bundle的任何值。这是一种在创建新实例时将某些类型的信息传递到片段中的有用方法。然后,您应该使用getFragmentManager而不是getSupportFragmentManager。如果您的应用程序目标为minSDKVersion-11,则无需使用getSupportFragmentManager,因为getFragmentManager()可以使用,然后您也可以使用objectAnimator。如果我想将其与支持库一起使用,该怎么办?非常感谢您的回答,我以另一种方式计算:@Glennsona您能告诉我们对您有效的另一种方式是什么吗?