0
我希望我的意见逐渐显现。所以我使用Timer来延迟视图出现的时间。但它不起作用。奇怪的是,这些意见同时出现! 这是我的代码。为什么我的视图在同一时间开始动画?
public static void startAnimations(final View... views) {
//assume 720
int screenWidth = 720;
final TranslateAnimation translateAnimation = new TranslateAnimation(-screenWidth/2, 0, 0, 0);
final AlphaAnimation alphaAnimation = new AlphaAnimation(0.5f, 1);
translateAnimation.setDuration(800);
alphaAnimation.setDuration(800);
mViewIndex = 0;
final Timer timer = new Timer();
final Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
if (mViewIndex >= views.length) {
timer.cancel();
mViewIndex = 0;
return;
}
View view = views[mViewIndex];
final AnimationSet animationSet = new AnimationSet(true);
animationSet.setDuration(800);
animationSet.setInterpolator(new AccelerateInterpolator());
animationSet.addAnimation(alphaAnimation);
animationSet.addAnimation(translateAnimation);
view.startAnimation(animationSet);
mViewIndex++;
}
};
timer.schedule(new TimerTask() {
@Override
public void run() {
handler.sendEmptyMessage(0x11);
}
}, 0, 300);
}
尝试增加持续时间值。 – Rustam
我认为你的图像丢失了。 –
@Rustam所以......不可能有多个视图同时运行动画吗? – exkulo