在同一动画xml文件中应用两个动画

时间:2015-12-28 00:46:50

标签: android animation android-animation

我想知道是否可以在同一个xml文件中应用一个带有两个缩放动画的动画,假设我有

animation.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">

   <alpha
       android:fromAlpha = "1.0"
       android:toAlpha = "0.5"
       android:duration = "300">
   </alpha>
   <scale
       android:fromXScale = "1"
       android:toXScale = "1.3"
       android:fromYScale = "1"
       android:toYScale = "1.3"
       android:pivotX="50%"
       android:pivotY="50%"
       android:duration = "50">
   </scale>

   <scale
       android:fromXScale = "1"
       android:toXScale = "1.3"
       android:fromYScale = "1"
       android:toYScale = "1.3"
       android:pivotX="50%"
       android:pivotY="50%"
       android:duration = "50">
   </scale>

然后以某种方式在ImageView上应用此动画,以便它执行动画1然后动画2?

而不是创建两个单独的动画,并在第一个动画中添加动画侦听器,以便在完成动画时执行动画...

3 个答案:

答案 0 :(得分:2)

是的,你可以使用:

 android:ordering="sequentially"

用于设置,以便顺序动画。请查看this以获取更多信息。

答案 1 :(得分:0)

有可能。但重要的是,您为动画设置的时间持续时间。你可以做这样的事情。

Animation multipleAnimaiton;
       imageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    multipleAnimaiton= AnimationUtils.loadAnimation(getApplicationContext(), R.anim.animation);
                    bounceAnimation.setDuration(5000);
                    v.startAnimation(bounceAnimation);

                }
            });

希望有所帮助

答案 2 :(得分:0)

doInBackground(Void... params) {
        // TODO Auto-generated method stub
        try {
            StartAnimation1();
            StartAnimation2();
            Thread.sleep(5000);
        } catch (InterruptedException e) {

            e.printStackTrace();
        }
        return null;
    }
}

private void StartAnimation1() {

    Animation anim = AnimationUtils.loadAnimation(this, R.anim.alpha);
    anim.reset();
    RelativeLayout l = (RelativeLayout) findViewById(R.id.re_lay);
    l.clearAnimation();
    l.startAnimation(anim);

    anim = AnimationUtils.loadAnimation(this, R.anim.fade_in);
    anim.reset();
    ImageView iv = (ImageView) findViewById(R.id.iv_logo);

    iv.clearAnimation();
    iv.startAnimation(anim);
}

private void StartAnimation2() {
    Animation anim = AnimationUtils.loadAnimation(this, R.anim.alpha);
    anim.reset();
    RelativeLayout l = (RelativeLayout) findViewById(R.id.re_lay);
    l.clearAnimation();
    l.startAnimation(anim);

    anim = AnimationUtils.loadAnimation(this, R.anim.sequential);
    anim.reset();
    ImageView iv = (ImageView) findViewById(R.id.iv_logo_name);
    iv.clearAnimation();
    iv.startAnimation(anim);
}

希望有所帮助