片段过渡支持25.1.0与Recyclerview

我正在使用片段转换为回收站视图设置animation,使用25.0.1支持库和转换对于推送和popup目标片段正常工作。

我用来生成交易的代码是:

supportFragmentManager.beginTransaction() .replaceAddToBackStack(R.id.content, fragment) .addSharedElement(fragment, commonViews) .commit() 

现在我试图更新到支持库的25.1.0版本,并且popup式animation崩溃,因为转换没有find原始视图,并且正在崩溃:

 E/MessageQueue-JNI: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference at android.support.v4.app.FragmentTransitionCompat21.setNameOverridesOptimized(FragmentTransitionCompat21.java:339) at android.support.v4.app.FragmentTransition.configureTransitionsOptimized(FragmentTransition.java:232) at android.support.v4.app.FragmentTransition.startTransitions(FragmentTransition.java:111) at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2143) at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2092) at android.support.v4.app.FragmentManagerImpl.popBackStackImmediate(FragmentManager.java:822) at android.support.v4.app.FragmentManagerImpl.popBackStackImmediate(FragmentManager.java:775) at android.support.v4.app.FragmentActivity.onBackPressed(FragmentActivity.java:178) at App.ui.base.BaseActivity.onBackPressed(BaseActivity.kt:23) ... 

但是,如果我禁用“优化”,它工作正常。

 supportFragmentManager.beginTransaction() .replaceAddToBackStack(R.id.content, fragment) .addSharedElement(fragment, commonViews) .setAllowOptimization(false) .commit() 

我做错了什么?

编辑:我用来包装共享元素的扩展:

.replaceAddToBackStack

 fun<T : Fragment> FragmentTransaction.replaceAddToBackStack(containerView: Int, fragment: T, tag: String? = null) : FragmentTransaction { return replace(containerView, fragment, tag).addToBackStack(fragment.toString()) } 

.addSharedElement

 fun<T: Fragment, V: View> FragmentTransaction .addSharedElement(destination: T?, sharedViews: List<V>?, sharedTransform: TransitionSet? = null, enterTransition: Transition? = null, exitTransition: Transition? = null ) : FragmentTransaction { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { return this } if (destination == null || sharedViews == null) { return this } val fade = Fade() fade.duration = 150 destination.enterTransition = enterTransition ?: fade destination.allowEnterTransitionOverlap = false destination.allowReturnTransitionOverlap = false destination.exitTransition = exitTransition ?: fade destination.sharedElementEnterTransition = sharedTransform ?: DetailsTransition() destination.sharedElementReturnTransition = sharedTransform ?: DetailsTransition() sharedViews.forEach { this.addSharedElement(it, it.transitionName) } return this } 

Solutions Collecting From Web of "片段过渡支持25.1.0与Recyclerview"