Android SpinKit: Nice-Looking Loading Animations for Your App

Android SpinKit is a library that provides a set of pretty nice loading animations for your app. It makes quite simple to use animating views since it doesn’t require us to handle starting and stopping animations on correct states of activity/fragment. The library handles the entire process itself.

First, we add the following to project-level “build.gradle” file:

Second, we add the library dependency to module-level “build.gradle” file:

Now, we’re ready to use SpinKitView directly in layout XML file as follows:

In this example, we set the loading animation as “Circle” (spinning tiny circles in a circular path) by setting the style as @style/SpinKitView.Circle. There are plenty of options which can be seen below. The entire list of available animations can be found here:

We can also set the size of animation as “Large” or “Small” by simply adding the size to the style string, i.e. @style/SpinKitView.Large.Circle or @style/SpinKitView.Small.Circle. If we don’t set anything as size, as we did in the example above, the default size will be “Medium”.

The animation will be played automatically when the activity/fragment, that contains SpinKitView inside its layout, becomes visible. However, if you want to use these loading animations in an Android view, an ImageView for instance, you can do it programmatically as shown below. In that case, you need to call start() and stop() for the animating drawable, which is Wave for the example provided below, most appropriately inside onStart() and onStop() of activity/fragment.

That’s all for today. If you have any question regarding this post, leave a comment.

Leave a Reply

Your email address will not be published. Required fields are marked *