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

5.9k Views Asked by At

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

2

There are 2 best solutions below

3
splatte On BEST ANSWER

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();
0
Aditya Vyas-Lakhan On

I think this is completely based on animation,I suggest you to follow this demo,this is exactly what you looking for.

<com.like.LikeButton
app:icon_type="star"
app:circle_start_color="@color/colorPrimary"
app:like_drawable="@drawable/thumb_on"
app:unlike_drawable="@drawable/thumb_off"
app:dots_primary_color="@color/colorAccent"
app:dots_secondary_color="@color/colorPrimary"
app:circle_end_color="@color/colorAccent"
app:icon_size="25dp"
app:liked="true"
app:anim_scale_factor="2"
app:is_enabled="false"
/>

OUTPUT :

enter image description here