Multiple animations on 1 imageview android

后端 未结 5 1793
感动是毒
感动是毒 2021-02-02 10:42

I have 2 animations which are already working, i want to fade my train + tween my train on the same time. If I execute 1 of these lines it works. But if I try to execute both it

5条回答
  •  伪装坚强ぢ
    2021-02-02 11:11

    Can be done programatically using AnimatorSet class of android :

    final AnimatorSet mAnimatorSet = new AnimatorSet();
        mAnimatorSet.playTogether(
                    ObjectAnimator.ofFloat(img_view,"scaleX",1,0.9f,0.9f,1.1f,1.1f,1),
                    ObjectAnimator.ofFloat(img_view,"scaleY",1,0.9f,0.9f,1.1f,1.1f,1),
                    ObjectAnimator.ofFloat(img_view,"rotation",0 ,-3 , -3, 3, -3, 3, -3,3,-3,3,-3,0)
            );
    
    //define any animation you want,like above
    
    mAnimatorSet.setDuration(2000); //set duration for animations
        mAnimatorSet.start();
    

    this example will start all the 3 animation on the target view(imgView) at same time ,you can also use playSequentially .....

    For complete example check this out..

提交回复
热议问题