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

3
我正在尝试在不同活动的不同片段下实现共享元素转换,这些片段中包含了两个 FixedAspectImageView。目标也在 NestedScollView 下。
发生的一切只是在 Fragment1 中的轻微过渡和稍后在 Activity2 中加载 Fragment2 时的闪烁。
由于这些元素位于不同活动的片段下,因此已经尝试在 Activity2 的 onCreate 方法中使用 postponeEnterTransition() 方法,在 Fragment2 的 onCreateView 方法中使用 startPostponedEnterTransition() 方法。
OriginLayout:
<CardView>
   <LinearLayout>
       <FrameLayout>
           <FixedAspectImageView>
              transitionName:"image"


DestinationLayout:
<FrameLayout>
   <NestedScrollView>
       <LinearLayout>
           <FrameLayout>
               <FixedAspectImageView>
                  transitionName:"image"
1个回答

2
您正在过早执行 startPostponedEnterTransition(): 在 onCreateView 中,您的视图尚未创建和布局。它也不在 onViewCreated() 中,该方法在 onCreateView() 之后立即调用。
相反,您必须等待视图布局完成,使用 ViewTreeObserver 方法 或简单的 view.post(Runnable),然后才能执行 startPostponedEnterTransition()

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接