Reversing an Animation

前端 未结 8 477
清歌不尽
清歌不尽 2020-11-30 01:41

I have an ImageView that gets animated when it is added to a layout. When it is removed, I want to reverse the same animation.

Is there a way to reverse an animation

8条回答
  •  一个人的身影
    2020-11-30 02:12

    this worked for me

     ObjectAnimator anim = ObjectAnimator.ofFloat(imageViewUpb, "rotation", rotationAngle, rotationAngle + 180);
    
                if (linearLayoutb.getVisibility()==GONE){
    
                    linearLayoutb.setVisibility(VISIBLE);
                    anim.setDuration(500);
                    anim.start();
                    rotationAngle += 180;
                    rotationAngle = rotationAngle%360;
            imageViewUpb.animate().rotation(rotationAngle).setDuration(500).start();
    
                }else{
    
                    linearLayoutb.setVisibility(GONE);
                    anim.setDuration(500);
                    anim.start();
                    rotationAngle += 180;
                    rotationAngle = rotationAngle%180;
    imageViewUpDownb.animate().rotation(rotationAngle).setDuration(500).start();
    
                }
    

    linearlayoutb is the view that expands when the imageviewUpb faces up

    make int rotationAngle = 0; global parameter

提交回复
热议问题