简体   繁体   English

android碎片交易

[英]android Fragment Transaction

FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.setCustomAnimations(R.anim.fade_in, R.anim.fade_out);
        fragmentTransaction.replace(R.id.container, objFragment)
                .commit();

I wrote this code for adding animation during transaction. 我编写此代码是为了在交易期间添加动画。 this create the error: 这会产生错误:

java.lang.RuntimeException: Unknown animation name: objectAnimator
         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2339)
         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2413)
         at android.app.ActivityThread.access$800(ActivityThread.java:155)
         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317)
         at android.os.Handler.dispatchMessage(Handler.java:102)
         at android.os.Looper.loop(Looper.java:135)
         at android.app.ActivityThread.main(ActivityThread.java:5343)
         at java.lang.reflect.Method.invoke(Native Method)
         at java.lang.reflect.Method.invoke(Method.java:372)
         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
  Caused by: java.lang.RuntimeException: Unknown animation name: objectAnimator
         at android.view.animation.AnimationUtils.createAnimationFromXml(AnimationUtils.java:126)
         at android.view.animation.AnimationUtils.createAnimationFromXml(AnimationUtils.java:93)
         at android.view.animation.AnimationUtils.loadAnimation(AnimationUtils.java:74)

I believe you are trying to use objectAnimator in support fragments library, but it was added in Android Api level 11. 我相信您正在尝试在支持片段库中使用objectAnimator ,但这是在Android Api 11级中添加的。

Use 采用

getFragmentManager()

instead of 代替

getSupportFragmentManager()

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. 如果您在xml文件中声明了对象动画,请确保将其放入animator文件夹而不是anim文件夹,以告知android使用新的动画框架。

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). 异常消息表明您的xml资源中的动画格式错误,可能是因为您将动画制作者移到了该xml上是错误的(因为它们的表示法不同)。 You need to write it in proper way: http://developer.android.com/guide/topics/graphics/view-animation.html 您需要以正确的方式编写它: http : //developer.android.com/guide/topics/graphics/view-animation.html

I hope it helps! 希望对您有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM