等待动画完成然后执行代码

时间:2014-11-18 15:55:44

标签: android animation

我正在使用自定义动画库。

zoomin动画效果很好

YoYo.with(Techniques.ZoomIn).duration(700).playOn(retView);

但是,当从列表视图中删除行时(也来自sqlite),项目将被删除而不会缩小动画。 当我删除删除代码时,我可以看到缩小动画。

public void onClick(View v) {
      Log.d("HirakDebug", "tCA delete button pressed");
      String row = row_id;
      YoYo.with(Techniques.ZoomOut).duration(700).playOn(retView);
      taskslist.closeAnimate(pos);
      tasksDatabaseOperations.deleteItemWithTask(row_id);
      adapter.notifyDataSetChanged();
      cursor.requery();
   }

如何完成第一个动画然后删除呢?

1 个答案:

答案 0 :(得分:2)

You could try the follow, calling the delete methods after the animation has ended.

     YoYo.with(Techniques.ZoomOut)
    .withListener(new Animator.AnimatorListener() {
     @Override
       public void onAnimationStart(Animator animation) {

       }
       @Override
       public void onAnimationEnd(Animator animation) {
         tasksDatabaseOperations.deleteItemWithTask(row_id);
         adapter.notifyDataSetChanged();
         cursor.requery();
       }
       @Override
       public void onAnimationCancel(Animator animation) {

       }
       @Override
       public void onAnimationRepeat(Animator animation) {

       }
       })
    .duration(700)
    .playOn(retView);