How to animate an expand/collapse arrow for 180 degree when arrow is clicked?

1.1k views Asked by At

I have a expand more icon on linearLayout in expandable recycler view

Expand Arrow Icon

I want when click on linearLayout is clicked layout will expand and this icon will rotate with animation in 180 degrees like below-

enter image description here

here is my action code:

rotationAngle = rotationAngle == 0 ? 180 : 0;
expandArrow.animate().rotation(rotationAngle).setDuration(500).start();

where rotationalAngle=0; is declared globally.

Can you find me a proper solution?

2

There are 2 answers

0
Pein On
ImageV.animate().rotation(isExpanded()? -180 : 0  )
                        .setInterpolator(new SineInOut60())
                        .setDuration(2000)
                        .withLayer();
0
sajjad On

You can use an AnimationListener to set a new Drawable when Animation is finished:

expandArrow.animate().setListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animator) {
            
        }

        @Override
        public void onAnimationEnd(Animator animator) {
            expandIcon.setImageResource(R.drawable.arrow_up);
        }

        @Override
        public void onAnimationCancel(Animator animator) {

        }

        @Override
        public void onAnimationRepeat(Animator animator) {

        }
    }).rotation(rotationAngle).setDuration(500).start();