我想制作像多米诺骨牌效果一样的动画。 但是当我使用动画xml和for循环的处理程序时,它同时一起工作。
如何制作多米诺骨牌效果动画,例如在第一个按钮(星期一)开始后100毫秒开始下一个按钮(星期二)的动画?
我的hanlder方法
private void startAnimation(final ArrayList<View> vArr)
{
mon = (Button)findViewById(R.id.mon);
tue = (Button)findViewById(R.id.tue);
wed = (Button)findViewById(R.id.wed);
thu = (Button)findViewById(R.id.thu);
fri = (Button)findViewById(R.id.fri);
sat = (Button)findViewById(R.id.sat);
sun = (Button)findViewById(R.id.sun);
final Button[] weekDayList = {mon, tue, wed, thu, fri, sat, sun};
Handler handler = new Handler()
{
@Override
public void handleMessage(Message msg)
{
super.handleMessage(msg);
switch (msg.what)
{
case 3:
for (int i = 0; i < weekDayList.length; i++)
weekDayList[i].startAnimation(buttonDown);
sendEmptyMessageDelayed(4, 100);
break;
case 4:
break;
}
}
};
handler.sendEmptyMessage(3);
}
我的动画片xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:fromXScale="1.0"
android:toXScale="1.0"
android:fromYScale="1.0"
android:toYScale="0.0"
android:pivotX="50%"
android:pivotY="100%"
android:duration="500" />
</set>
答案 0 :(得分:-1)
将AnimationListener
设置为动画。使用onAnimationEnd()
开始下一个动画。
答案 1 :(得分:-1)
您可以使用ObjectAnimator
(自API 11起)执行此操作,并通过将所有动画添加到AnimatorSet
来顺序播放动画。
public void dominoAnimations() {
ObjectAnimator monAnimation = ObjectAnimator.ofFloat(mon, "scaleY", 0f);
ObjectAnimator tueAnimation = ObjectAnimator.ofFloat(tue, "scaleY", 0f);
ObjectAnimator wedAnimation = ObjectAnimator.ofFloat(wed, "scaleY", 0f);
ObjectAnimator thuAnimation = ObjectAnimator.ofFloat(thu, "scaleY", 0f);
ObjectAnimator friAnimation = ObjectAnimator.ofFloat(fri, "scaleY", 0f);
ObjectAnimator satAnimation = ObjectAnimator.ofFloat(sat, "scaleY", 0f);
ObjectAnimator sunAnimation = ObjectAnimator.ofFloat(sun, "scaleY", 0f);
AnimatorSet dominoes = new AnimatorSet();
dominoes.playSequentially(
monAnimation, tueAnimation, wedAnimation,
thuAnimation, friAnimation, satAnimation, sunAnimation
);
dominoes.setDuration(500);
dominoes.start();
}