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