0

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?

aynber
  • 22,380
  • 8
  • 50
  • 63
Sayem Hossen
  • 27
  • 1
  • 10

2 Answers2

1

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();
sajjad
  • 834
  • 6
  • 13
1
ImageV.animate().rotation(isExpanded()? -180 : 0  )
                        .setInterpolator(new SineInOut60())
                        .setDuration(2000)
                        .withLayer();
Pein
  • 33
  • 4