2017-09-13 62 views
0

我目前正在嘗試使用片段的共享元素轉換,並具有工作的基本思想。我有兩個非常相似的屏幕(見屏幕截圖),共享轉換適用於表單,但兩個按鈕(登錄/社交)不會優雅地過渡,它們在退出時會消失,並在進入時再次出現。是否可以指定這兩個視圖項目在轉換期間淡出和淡入?如何在片段轉換中淡出非共享視圖?

片段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)); 

Screenshot

+0

試試這個答案https://stackoverflow.com/questions/28386397/shared-element-transitions-between-views-not-activities-or-fragments –

回答

0

所以更多的挖掘後,我已經瞭解到,非共享視圖被稱爲transitioning views作爲在這裏陳述在AndroidDesignPatterns.com

內容轉換確定活動的非共享視圖(也稱爲轉換視圖)如何進入或退出活動場景。

,並從同一網站

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. 

另一個article發現原來這簡單的一行解決我的問題。

setExitTransition(TransitionInflater.from(getActivity()).inflateTransition(android.R.transition.fade));