如何淡出片段过渡中的非共享视图?
How to fade out non shared views in fragment transition?
我目前正在尝试使用片段进行共享元素转换,并且基本想法可行。我有两个非常相似的屏幕(见屏幕截图),并且共享过渡适用于表单,但是两个按钮 (login/social) 没有优雅地过渡,它们只是在退出时消失,并在进入时重新出现。是否可以指定这两个视图项在过渡期间淡出和淡入?
片段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));
所以在进一步挖掘之后,我了解到非共享视图被称为 transitioning views
,如 AndroidDesignPatterns.com
中所述
A content transition determines how an activity’s non-shared views (also called transitioning views) enter or exit the activity scene.
并在同一网站的另一个 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));
我目前正在尝试使用片段进行共享元素转换,并且基本想法可行。我有两个非常相似的屏幕(见屏幕截图),并且共享过渡适用于表单,但是两个按钮 (login/social) 没有优雅地过渡,它们只是在退出时消失,并在进入时重新出现。是否可以指定这两个视图项在过渡期间淡出和淡入?
片段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));
所以在进一步挖掘之后,我了解到非共享视图被称为 transitioning views
,如 AndroidDesignPatterns.com
A content transition determines how an activity’s non-shared views (also called transitioning views) enter or exit the activity scene.
并在同一网站的另一个 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));