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

uqxowvwt  于 2023-02-17  发布在  Android
关注(0)|答案(3)|浏览(155)

我想知道是否有可能在同一个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?
而不是创建两个单独的动画,并添加一个动画侦听器到我的第一个动画执行animation2时,一个完成...

k0pti3hp

k0pti3hp1#

是,您可以用途:

android:ordering="sequentially"

对于设置,所以它动画顺序。看看this为进一步的信息。

b5buobof

b5buobof2#

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

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);

                }
            });

希望能有所帮助

laik7k3q

laik7k3q3#

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);
}

希望能有所帮助

相关问题