2013-02-19 37 views
0

我試圖實現同種動畫單擊通知欄中的「全部清除」按鈕,當這種情況發生的:如何複製果凍豆「清除所有通知」動畫

normal clear all

這就是我現在的(對於ListView),但它不能正常工作。由於時間/暫停,我想。

Animation animation = AnimationUtils.loadAnimation(getActivity(), android.R.anim.slide_out_right); 
animation.setDuration(300); 

int count = mNotificationList.getCount(); 
for (int i = 0; i < count; i++) { 
    View view = mNotificationList.getChildAt(i); 

    if (view != null) 
     view.startAnimation(animation); 
} 

任何人都知道如何完成動畫?

回答

0

爲了達到這樣的效果,您應該爲每個項目使用不同的Animation,因此您可以通過Animation.setStartOffset(long)方法輕鬆設置不同的起始偏移量。

您的代碼應該是這樣的:

int count = mNotificationList.getCount(); 
for (int i = 0; i < count; i++) { 
    View view = mNotificationList.getChildAt(i); 
    if (view != null) { 
     // create an Animation for each item 
     Animation animation = AnimationUtils.loadAnimation(
      getActivity(), 
      android.R.anim.slide_out_right); 
     animation.setDuration(300); 

     // ensure animation final state is "persistent" 
     animation.setFillAfter(true); 

     // calculate offset (bottom ones first, like in notification panel) 
     animation.setStartOffset(100 * (count - 1 - i)); 

     view.startAnimation(animation); 
    } 
} 
+0

非常好,謝謝你。 – Mike 2013-02-19 15:39:08