我目前正在尝试使用片段进行共享元素转换,并且基本想法正常运行。我有两个非常相似的屏幕(见屏幕截图),共享转换适用于表单,但两个按钮(登录/社交)没有优雅地转换,它们在退出时消失,并在进入时重新出现。是否可以指定这两个视图项在过渡期间淡出和淡入?
片段A
getActivity().getSupportFragmentManager().beginTransaction()
.addSharedElement(btn_next, ViewCompat.getTransitionName(btn_next))
.addSharedElement(et_email, ViewCompat.getTransitionName(et_email))
.addSharedElement(ll_form, ViewCompat.getTransitionName(ll_form))
.replace(R.id.fl_content, new LoginFragment())
.addToBackStack(null)
.commit();
片段B
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setSharedElementEnterTransition(TransitionInflater.from(getContext()).inflateTransition(android.R.transition.move));
答案 0 :(得分:1)
因此,经过一番挖掘,我了解到非共享视图被称为transitioning views
,如AndroidDesignPatterns.com所述
内容转换确定活动的非共享视图(也称为转换视图)如何进入或退出活动场景。
并在同一网站的另一个article找到
setExitTransition() - A’s exit transition animates transitioning views out of the scene when A starts B.
setEnterTransition() - B’s enter transition animates transitioning views into the scene when A starts B.
setReturnTransition() - B’s return transition animates transitioning views out of the scene when B returns to A.
setReenterTransition() - A’s reenter transition animates transitioning views into the scene when B returns to A.
所以这个简单的一行解决了我的问题。
setExitTransition(TransitionInflater.from(getActivity()).inflateTransition(android.R.transition.fade));