Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 222
Gaurav Singhal Avatar asked Jun 28 '16 06:06

Gaurav Singhal


1 Answers

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();
like image 135
splatte Avatar answered Oct 13 '22 01:10

splatte