我试图使用值动画师一个接一个地动画3个图像,但是我无法决定如何在定期间隔后调用三个处理程序.假设有3个图像并且我正在制作三个处理程序来动画它们.但我能够一次带三个图像,但不是一个接一个地定期播放.请帮助
这是我从我的处理程序调用的UpdateListener
public void startAnimation_image(final ImageView aniView) {
animator = ValueAnimator.ofFloat(0, .8f);
animator.setDuration(Constants.ANIM_DURATION);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
int Low = 10;
int High = width-150;
int R = (int) ((Math.random() * (High - Low)) + Low);
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float value = ((Float) (animation.getAnimatedValue())).floatValue();
aniView.setTranslationX(R);
Log.e("mscale",150*mScale +"");
Log.e("value is", value+"");
aniView.setTranslationY((mDisplaySize.bottom + (150*mScale))*value);
x_point = aniView.getTranslationX();
y_point = aniView.getTranslationY();
}
});
animator.addListener(new AnimatorListener() {
@Override
public void onAnimationStart(Animator arg0) {
}
@Override
public void onAnimationRepeat(Animator arg0) {
}
@Override
public void onAnimationEnd(Animator arg0) {
startAnimation();
}
@Override
public void onAnimationCancel(Animator arg0) {
}
});
animator.start();
}
Run Code Online (Sandbox Code Playgroud)
这是我的处理程序之一
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
//int viewId = new Random().nextInt(STARS.length);
id = getApplicationContext().getResources().getIdentifier(STARS[0], "drawable",
getApplicationContext().getPackageName());
inflate = LayoutInflater.from(StarsActivity2.this);
img[0].setVisibility(ImageView.VISIBLE);
img[0].setImageResource(id);
mAllImageViews.add(img[0]);
LayoutParams animationLayout = (LayoutParams) img[0].getLayoutParams();
img[0].setLayoutParams(animationLayout);
Log.e("mHandler",img[0]+ "");
startAnimation_image(img[0]);
}
};
Run Code Online (Sandbox Code Playgroud)
有类似的三个处理程序和三个更新听众..请帮助...
offset您可以通过调用将动画延迟毫秒
animation.setStartOffset(offset);
Run Code Online (Sandbox Code Playgroud)
因此,对于持续时间为三个图像ANIM_DURATION,您可以使用以下值按顺序启动它们(可能通过将它们作为参数传递给startAnimation_image())
// note: this is for illustrative purposes. You should put this in a loop
int firstOffset = 0 * ANIM_DURATION; // starts immediately
int secondOffset = 1 * ANIM_DURATION; // starts after the first animation is finished
int thirdOffset = 2 * ANIM_DURATION; // starts after the second animation is finished
// ... and so on.
Run Code Online (Sandbox Code Playgroud)