How to animate an item in a tab layout when selecting a tab?

I want to put an animation when I click on a tab, I want an animation to rotate the image on a tab. Below is an example, but it is on iOS.

enter image description here

+6
source share
2 answers

The following approach might work: create an AnimatedVectorDrawable , as shown here https://developer.android.com/reference/android/graphics/drawable/AnimatedVectorDrawable.html , and set it as a tab icon.

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

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

I think this is entirely based on animation, I suggest you follow this demo, this is exactly what you are 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" /> 

EXIT:

enter image description here

+1
source

All Articles