不同活动片段之间的共享元素转换

Shared element transition in between fragments of different activities

我正在尝试实现位于不同 activity 的不同片段下的两个 FixedAspectImageView 之间的共享元素转换。目标也在 NestedScollView 下 发生的一切只是 Fragment1 的闪烁,略微过渡,而不是在 Activity2 中加载 Fragment2

由于元素位于不同 activity 的片段之下,已尝试在创建 Activity2 和 startPostponedEnterTransition()[ 时使用 postponeEnterTransition()在Fragment2的onCreateView中。

OriginLayout:
<CardView>
   <LinearLayout>
       <FrameLayout>
           <FixedAspectImageView>
              transitionName:"image"


DestinationLayout:
<FrameLayout>
   <NestedScrollView>
       <LinearLayout>
           <FrameLayout>
               <FixedAspectImageView>
                  transitionName:"image"

您执行 startPostponedEnterTransition() 太早了:在 onCreateView 您的视图尚未创建和布局。它也不在 onViewCreated() 中,后者在 onCreateView().

之后调用

相反,您必须等到使用 ViewTreeObserver approach 或普通 view.post(Runnable) 布局视图,然后才执行 startPostponedEnterTransition().