1

in this questionのメソッドを実装しました。しかし、最初のリスト塗りアニメーションは、同時にすべてのオブジェクトが画面に表示され、ちょうど遅れのように見えることを示しています。RecyclerViewアイテムはリスト塗りでアニメーションされますが、最初のアイテムはすべて同時にアニメーション化され、遅れのように見えます

デバッグ中に、アニメーションメソッドが7回呼び出されているのがわかりますが、それは非常に速く、基本的に同時に実行しようとしています。私は何ができるのですか?私はアニメーションを遅らせることを試みたが、私はそれをする方法に立ち往生した。私はその質問にお答えしましたhere.助けてくれてありがとう!

編集:

public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position) 
    { 
     //Normal OnBindViewHolder stuff 
     SetAnimation(vh.ItemView, position); 
    } 

そしてSetAnimation方法:

private void SetAnimation(View viewToAnimate, int position) 
    { 
     if (position > lastPosition) 
     { 
      var animation = AnimationUtils.LoadAnimation(_context, Resource.Animation.up_from_bottom); 
      //animation.SetAnimationListener(new CheckpointAnimationListener()); 
      viewToAnimate.StartAnimation(animation); 
      lastPosition = position; 
     } 
    } 

私は本当にここで何をしたいですが、アニメーションのためである私は、私は他の質問に置く同じコードを投稿することができますlastPostion = position行が呼び出される前に終了します。

空のAnimationListener。私は実際に待機を処理する方法がわかりません。

private class CheckpointAnimationListener : Java.Lang.Object, Animation.IAnimationListener 
    { 
     public void OnAnimationEnd(Animation animation) 
     { 

     } 

     public void OnAnimationRepeat(Animation animation) 
     { 

     } 

     public void OnAnimationStart(Animation animation) 
     { 

     } 
    } 

答えて

0

Gilからの答えは正しい方向に私を送りましたが、私はXamarin.Androidと一緒に作業しているので、私はいくつかのことを別々に行う必要がありました。代わりにStartOffsetのアイデアを使用しました.C#は匿名クラスを使用しないためです(ランナブルをかなり難しくしています)。ここに私の最終的なアニメーションコードがあります(遅れて遊んだ後)。

private int lastPosition = -1; 
    private long _nextAnimationStartTime = 0; 
    private long _currentTime = 0; 
    private long _timeAtFirstCall = JavaSystem.CurrentTimeMillis(); 
    private long _delay = 150; 

このメソッドはOnBindViewHolderの最後に呼び出されます:

private void SetAnimation(View viewToAnimate, int position) 
    { 
     var animation = AnimationUtils.LoadAnimation(_context, Resource.Animation.up_from_bottom); 

     _currentTime = JavaSystem.CurrentTimeMillis(); 

     long difference = _currentTime - _timeAtFirstCall; 

     //this will cause the first items to populate the view to animate in order instead of at the same time. 
     //_delay is increased each time so each item will start 75ms after the one before it. difference is 
     //there to make sure later items in the list dont get this delay and animate as they appear. 
     if (_nextAnimationStartTime > _currentTime && difference < 150) 
     { 
      if (position > lastPosition) 
      { 
       animation.StartOffset = _delay; 
       viewToAnimate.StartAnimation(animation); 
       lastPosition = position; 
       _delay += 75; 
      } 

     } 
     else 
     { 
      if (position > lastPosition) 
      { 
       animation.StartOffset = 75; 
       viewToAnimate.StartAnimation(animation); 
       lastPosition = position; 
      } 
     } 

     _nextAnimationStartTime = _currentTime + 400; 

    } 

そして私は、これらの変数が定義されたクラスの先頭に初期化されていました。これで、OnBindViewHolderが初めて呼び出されたときに、elseステートメントが実行されます。そうでなければ、アニメーションは画面の半分から始まり、ちょうど悪く見えたからです。この遅延によって、アイテムは高速スクロールで順番にアニメートされます。

ビューをロードするとき、私はまだ持っている一つの問題は、直ちに場合は、ユーザーがスクロールです。最初のアイテムは遅延を維持しますが、スクロールするとアニメートするように設定されている最初のアイテムは、最初のアイテムが終了する前にアニメーションを開始する可能性があります。私はこの問題を回避する方法がわかりません...

0

私は同様のことをしなければなりませんでした。基本的には、アニメーションを開始するたびに、アニメーションが開始された最後の時間に基づいて、最小開始時間をいつ通知するかということでした。

あなたが任意のコードを投稿していなかったので、私は私がやったことの基本的な概要を記述しますが:

// member to know when the minimum start time of the next animation will be. 
private long mNextAnimationStartTime; 

... 

public void onBindViewHolder(...) { 
    // perform binding logic 

    // sample the current time. 
    long currentTime = System.currentTimeMillisec(); 

    // if the next animation time is greater than now... 
    if (mNextAnimationStartTime > currentTime) { 

     // calculate how much time to wait before showing the next animation. 
     int delay = mNextAnimationStartTime - currentTime; 

     // In this example, I use postDelayed to postpone the animation, 
     // but you could also use start offset of the animation itself. 
     postDelayed(new Runnable() { 
      @Override 
      public void run() { 

       // start the animation after a delay. 
       startAnimation(viewToAnimate); 
      } 
     }, delay); 
    } else { 

     // if the next animation time is in the past, just start the animation. 
     startAnimation(viewToAnimate); 
    } 

    // schedule the next animation start time to now + 100 ms (play with this 100 to fit your needs) 
    mNextAnimationStartTime = currentTime + 100; 
} 

希望これは明らかになった、とあなたが始めるのに役立ちます。

+0

私の前の質問から私のコードをコピーして、これに入れてください。しかし、あなたのコードは、どこに行くのよいアイデアを与えるのですか?私はXamarin.Androidで作業しているので、いくつかのことを別々に行う必要がありますが、あなたのアイデアは良いものです。 –

関連する問題