3
我想在6個球上播放比例(從0 - > 1)動畫,每個球的持續時間是1000毫秒。安卓動畫問題
並且每個動畫必須等待200ms以前。
例如:
anim1.start - >延遲爲200ms - > anim2.start(而anim1正在播放) - > ........
,但我始終得到了所有6個球動畫在同一時間開始,我不知道爲什麼,可以
有人告訴我??
// show animation.
public void showBallAnimation(View v) {
LinearLayout ll = (LinearLayout) findViewById(R.id.ball_container);
RelativeLayout rl;
ScaleAnimation scaleAnim1 = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f);
scaleAnim1.setDuration(500);
scaleAnim1.setStartOffset(0);
scaleAnim1.setFillAfter(true);
rl = (RelativeLayout) ll.getChildAt(0);
rl.setVisibility(View.VISIBLE);
rl.startAnimation(scaleAnim1);
ScaleAnimation scaleAnim2 = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f);
scaleAnim2.setDuration(500);
scaleAnim2.setStartOffset(200);
scaleAnim2.setFillAfter(true);
rl = (RelativeLayout) ll.getChildAt(1);
rl.setVisibility(View.VISIBLE);
rl.startAnimation(scaleAnim2);
ScaleAnimation scaleAnim3 = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f);
scaleAnim3.setDuration(500);
scaleAnim3.setStartOffset(400);
scaleAnim3.setFillAfter(true);
rl = (RelativeLayout) ll.getChildAt(2);
rl.setVisibility(View.VISIBLE);
rl.startAnimation(scaleAnim3);
// Animation anim4 =
// AnimationUtils.loadAnimation(getApplicationContext(),
// R.anim.ball_scale4);
ScaleAnimation scaleAnim4 = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f);
scaleAnim4.setDuration(500);
scaleAnim4.setStartOffset(600);
scaleAnim4.setFillAfter(true);
rl = (RelativeLayout) ll.getChildAt(3);
rl.setVisibility(View.VISIBLE);
rl.startAnimation(scaleAnim4);
}
只是在黑暗中拍攝 - 你有沒有設置開始時間? http://developer.android.com/reference/android/view/animation/Animation.html#setStartTime(long) - 鏈接不工作,搜索「setStartTime」。另外「作爲startAnimation()的替代方法,您可以使用Animation.setStartTime()定義動畫的開始時間,然後使用View.setAnimation()將該動畫分配給視圖。」 - http://developer.android.com/guide/topics/graphics/view-animation.html –