2017-07-28 69 views
2

我試圖從支持庫中使用TransitionManager.beginDelayedTransition()來延遲轉換。使用Transitions框架延遲動畫

我想使用AutoTransition使LinearLayout出現/消失。該動畫完美如預期,但不會延遲。

TransitionManager.beginDelayedTransition(rootViewGroup, new AutoTransition().setStartDelay(1000)); 
linearLayout.setVisibility(View.VISIBLE); 

linearLayout是當然的rootViewGroup的層次結構。

+1

打開了一個機票https://issuetracker.google.com/issues/64139005 –

回答

0

我做了一些測試,但不幸的是我也無法使它工作。它看起來像setStartDelay只適用於ChangeBounds過渡。

請看下面的例子(當您將在first過渡startDelay,延遲將無法正常工作):

linearLayout = (LinearLayout) findViewById(R.id.testLinearLayout); 
mSceneRoot = (ViewGroup) findViewById(R.id.rootView); 
mStaggeredTransition = new TransitionSet(); 

Transition first = new Fade(Fade.OUT); 
Transition second = new ChangeBounds(); 
Transition third = new Fade(Fade.IN); 
second.setStartDelay(1000).addTarget(linearLayout); 

mStaggeredTransition.setOrdering(ORDERING_SEQUENTIAL); 
mStaggeredTransition.addTransition(first).addTransition(second).addTransition(third); 

findViewById(R.id.testbutton).setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View v) { 
     linearLayout.setVisibility(View.GONE); 
     TransitionManager.beginDelayedTransition(mSceneRoot, mStaggeredTransition); 
     linearLayout.setVisibility(View.VISIBLE); 
     RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) linearLayout.getLayoutParams(); 
     params.addRule(ALIGN_PARENT_END); 
     linearLayout.setLayoutParams(params); 
    } 
}); 

所以我建議你使用這樣的:

mSceneRoot.postDelayed(new Runnable() { 
     @Override 
     public void run() { 
      TransitionManager.beginDelayedTransition(rootViewGroup, new AutoTransition().setStartDelay(1000)); 
      linearLayout.setVisibility(View.VISIBLE); 
     } 
    }, 1000); 
+0

我不想使用'Handler',因爲我必須處理潛在的內存泄漏......但看起來像是要走的路。謝謝Jordy –