我有一个方法需要4秒才能执行,如果用户在结束之前再次调用它而不是刷新,我想只在最后一个完成后启动新的,将它们放入队列中。 / p>
我已经阅读了documentation,但我仍然不知道如何实现它,有人可以提供一个例子吗?
代码
我的方法:
public void popClassAdded(int amount){
classAddedText.setText(getString(R.string.you_earned) + amount + " ");
setIn = new AnimatorSet();
setIn.playTogether(
Glider.glide(Skill.QuintEaseOut, 200, ObjectAnimator.ofFloat(classAddedLayout, "translationY", -50, 165))
);
setIn.setDuration(1200);
classAddedLayout.setVisibility(View.VISIBLE);
setIn.start();
classAddedLayout.postDelayed(new Runnable(){
public void run(){
AnimatorSet set = new AnimatorSet();
set.playTogether(Glider.glide(Skill.CubicEaseInOut, 200, ObjectAnimator.ofFloat(classAddedLayout, "translationY", 165, -50)));
set.setDuration(1200);
set.start();
set.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) { }
@Override
public void onAnimationEnd(Animator animation) {
classAddedLayout.setVisibility(View.GONE);
}
@Override
public void onAnimationCancel(Animator animation) { }
@Override
public void onAnimationRepeat(Animator animation) { }
});
}
},2000);
shopPrefs.edit().putInt("coins", amount + shopPrefs.getInt("coins", 0)).apply();
}
致电:
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//may get clicked more than once in an interval or 4 seconds
((Activity_Main)getActivity()).popClassAdded(100);
}
});