androidanimationandroid-tablayouttabwidget

How to animate item in Tab Layout when select a tab?


I want to put an animation when i am taping the tab i want image rotation animation on tab icon. Below is the Example but it is in iOS.

enter image description here


Solution

  • The following approach might work: Create an AnimatedVectorDrawable as illustrated here https://developer.android.com/reference/android/graphics/drawable/AnimatedVectorDrawable.html and set it as your tab's icon.

    Assign a listener to your TabLayout, in TabLayout.OnTabSelectedListener#onTabSelected(TabLayout.Tab tab) you have access to the tab's icon using tab.getIcon(). Run the animation associated with your AnimatedVectorDrawable like so:

    final Drawable icon = tab.getIcon();
    ((Animatable) icon).start();