Android Shimmer Effect with Recyclerview

Achmad Qomarudin
3 min readDec 9, 2020

--

Shimmer Recyclerview is an Android library that provides an easy way to add a shimmer effect to any view in your Android app.

Simmer is an android layout which nest any view inside it using a ShimmerRecyclerview library. You can specify the values for the layout either on the tag(using attribute value from this library) or programmatically in your code, and generate an animation on the fly.

Source from :

There are two kinds of shimmer animation which you can see here:

1.) This type of shimmer effect uses the whole ViewHolder item to animate on. For example is below :

  • List Demo
https://github.com/achmadqomarudin/ShimmerRecyclerView/blob/master/screenshots/1.gif
  • Grid Demo
https://github.com/achmadqomarudin/ShimmerRecyclerView/blob/master/screenshots/2.gif

2.) Here the shimmer effect only applied on for those views which background color is nontransparent. For example is below :

  • List Demo
https://github.com/achmadqomarudin/ShimmerRecyclerView/blob/master/screenshots/3.gif
  • Grid Demo
https://github.com/achmadqomarudin/ShimmerRecyclerView/blob/master/screenshots/4.gif

Shimmer effect types

  1. As you can see the first demo examples show that the whole ViewHolder item is animated. To achieve the desired effect, the children of the ShimmerLayout should have a nontransparent background.
  2. You can achieve the second kind of shimmer effect by adding only one ViewGroup child to the ShimmerLayout with a transparent background. This ViewGroup will have the other views with nontransparent backgrounds on which the effect will be seen. You may wonder how can you add background to the root view of the ViewHolder, if you do not have direct access to the ShimmerLayout and the only child has a nontransparent background. The solution for this is to use the shimmer_demo_view_holder_item_background attribute.

Attributes and Methods

Following are the attributes and methods to initialise the demo views.

Screenshot by myself

Setup

  • Add the following configuration in your build.gradle file.
repositories {
...
maven { url "https://jitpack.io" }
...
}
dependencies { implementation 'com.github.sharish:ShimmerRecyclerView:v1.3'
}

Usage

  • Define your xml as:
<com.cooltechworks.views.shimmer.ShimmerRecyclerView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/shimmer_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:shimmer_demo_child_count="10"
app:shimmer_demo_grid_child_count="2"
app:shimmer_demo_layout="@layout/layout_demo_grid"
app:shimmer_demo_layout_manager_type="grid"
app:shimmer_demo_angle="20"
/>

where @layout/layout_demo_grid refers to your sample layout that should be shown during loading spinner. Now on your activity onCreate, initialize the shimmer as below:

ShimmerRecyclerView shimmerRecycler = (ShimmerRecyclerView) findViewById(R.id.shimmer_recycler_view);
shimmerRecycler.showShimmerAdapter();

Conclusion

In this article, we learned how to create a Shimmer Effect in Android using ShimmerRecyclerView with Library. We also create a sample application that gives the clarity of shimmer recyclerview implementation.

That’s it. Now you have learn the implementation of the Shimmer Recyclerview. Find full source code in below :

Questions? Comments? Contact us at yourfriends.medium.com

--

--

Achmad Qomarudin
Achmad Qomarudin

Written by Achmad Qomarudin

Android Developer • UI/UX Enthusiast • Love to create apps exploration on github.com/achmadqomarudin • Have a question? find me on instagram.com/achmad_dev

No responses yet