Shimmer Effect in RecyclerView: Android Kotlin Guide
A shimmer placeholder tells the user "content is on the way" far better than a centred spinner, especially on list screens where the layout is already known. Instead of a blank area, you draw grey blocks in the shape of your future rows and sweep a soft highlight across them until the network call finishes.
This guide builds that from scratch with RecyclerView and Kotlin: one skeleton item layout, a small shimmer drawable, and an adapter that swaps between skeleton and real data. We will also cover the parts that bite in production, like turning the animation off when data arrives and keeping the shimmer cheap on low-end devices.
Why a Skeleton Beats a Spinner on List Screens
A progress spinner communicates only that something is loading. A skeleton communicates what is loading: the shape of a card, the number of rows, the position of an avatar and two text lines. Users perceive the screen as faster because the layout does not jump when data lands, and because their eye is already in the right place when the content appears.
The effect only works if the skeleton roughly matches the final item. If your skeleton shows a 56dp avatar circle and the real row shows a 24dp icon, the transition looks broken. Sketch the real item first, then strip it down: keep the container sizes and margins, replace images with grey boxes, and replace text with bars of one to three widths.
Keep the skeleton count close to what fits on screen. Ten to twelve rows cover most phones; anything beyond that is invisible work that still costs layout and draw time on every frame.
- Skeleton should mirror real item dimensions, not approximate them
- Use 2-3 text bar widths so rows do not look identical
- Show enough rows to fill the viewport, plus one
- Never show shimmer over stale content; clear the list first
The Skeleton Item Layout
The skeleton row is a plain ConstraintLayout or LinearLayout with grey View blocks. Give each block a background drawable with a rounded corner radius of 4-8dp and a colour of about #E0E0E0 in light theme, #2A2A2A in dark theme. Text lines are 12-14dp tall Views, not TextViews, because you never render text in them.
Set android:importantForAccessibility="no" on the whole skeleton container. Screen readers should not announce a dozen meaningless grey boxes; a single content description like "Loading content" on the RecyclerView is enough while the skeleton is visible.
Put the shimmer overlay on a parent FrameLayout that wraps the RecyclerView, not inside each item. One animation across the whole list looks more natural and costs far less than twelve simultaneous item-level animations.
Writing the Shimmer Drawable and Animating It
A shimmer is a linear gradient with a light band between two base colours. Build it as a ShapeDrawable with a LinearGradient for the sweep and a base colour underneath, or use a simple custom Drawable that offsets the gradient matrix each frame. The offset is what moves: shift it from minus the view width to plus the view width and the highlight appears to travel across.
Drive it with a ValueAnimator over roughly 1000-1500ms with a LinearInterpolator, repeat infinite, and set the animated value into the drawable's matrix translation. Below about 800ms the sweep looks nervous; above 2000ms it feels sluggish and users start to think the app has frozen.
Always call animator.cancel() when the data arrives and in onDestroyView of your Fragment. A repeating ValueAnimator that keeps running after the screen is gone is a classic leak and a quiet battery drain.
- Base colour: #E0E0E0 light, #2A2A2A dark
- Highlight: base colour lightened by 8-12%
- Duration: 1000-1500ms, LinearInterpolator
- Cancel the animator in onDestroyView
Swapping Between Skeleton and Data
Keep one adapter that renders two view types: SKELETON and ITEM. A sealed class or an enum field on a small UI model is enough. When loading starts, submit a list of ten skeleton models and show the shimmer overlay. When the response arrives, submit the real list and hide the overlay in the same frame.
Do not call notifyDataSetChanged. Submit the new list through ListAdapter with a DiffUtil item callback, or through a submitList-style call if you use Paging 3. DiffUtil handles the transition cleanly and keeps scroll position when you append a second page of results.
If you use data binding for the rows, remember that binding expressions are evaluated on rebind, so a skeleton flag on the model is fine, but toggling visibility in the adapter also works and is easier to debug when the row starts misbehaving. The same rebind discipline matters when you wire Data Binding into a RecyclerView.
Performance and Edge Cases
An animating gradient forces a redraw of the shimmer view every frame. On a mid-range phone that is cheap for one full-screen view, but it is not free on top of image loading. Pause the animator when the RecyclerView is not visible, and consider skipping the shimmer entirely when the system animation scale is 0, which signals the user disabled animations.
Handle empty and error states explicitly. If the request fails, replace the skeleton with an error row and a retry button; a shimmer that runs forever is worse than a spinner because it looks like the app is still working when it is not. Add a timeout of 10-15 seconds to your network call so this state is reachable.
Finally, test with a deliberately throttled connection. On a fast network the shimmer flashes for 80ms and looks like a glitch; many teams add a 300-500ms minimum display time so the effect reads as intentional. The number of views in the skeleton matters too, so keep it lean, as covered in how many widgets a typical screen uses.
| Approach | Typical sweep duration | Views involved | Best for |
|---|---|---|---|
| Item-level shimmer drawable | 1000-1500ms | One per visible row (8-12) | Small lists, simple rows |
| Overlay on list container | 1000-1500ms | One | Most list screens |
| Static skeleton, no animation | None | One per row | Low-end devices, reduced motion |
| Library component | 600-2000ms (configurable) | One or more | Many screens, shared config |
| Spinner only | N/A | One | Unknown layout, very short loads |
Where the Shimmer Code Lives in Your Architecture
Keep the shimmer state in the ViewModel as a UiState sealed class: Loading, Success(list), Empty, Error. The Fragment observes that state and only decides how to render it. This makes the loading behaviour testable without touching animations, and it prevents the classic bug where two parallel requests both try to hide the shimmer.
If you are already loading pages with coroutines, cancel the previous job before starting a new one, otherwise a slow first request can overwrite a fast second one. The mistakes around job cancellation are the same ones described in common Kotlin coroutines mistakes with numbers.
Choosing Between a Library and Hand-Rolled Code
A shimmer library gives you the drawable and animator in a few lines, but it also adds a dependency, and many are unmaintained. The hand-rolled version in this article is around 80 lines, has no dependency, and lets you tune the gradient and timing to your design system, which matters when your brand colour is not grey.
Write it yourself if you have one or two list screens. Reach for a library only if you need the same treatment across a dozen screens and want a single place to change the speed. Either way, the adapter and UiState structure above stays the same, so switching later is a small change.
Testing the Loading State
Test the skeleton path deliberately: add a debug flag that delays the repository response by two seconds, then navigate through every list screen and watch the transition. Check for flicker, for a skeleton that does not match the real row heights, and for a shimmer that keeps running after you press back.
On the JVM side, test the ViewModel state machine: emit Loading, then Success, and assert the order. Animation itself does not need a unit test; the state that decides whether it runs does.
Key points
- Match skeleton dimensions to the real row; mismatched skeletons look broken on swap
- One overlay animator on the RecyclerView beats per-item animations
- Cancel the animator when data arrives and in onDestroyView to avoid leaks
- Model loading as a UiState in the ViewModel so the shimmer is testable
Flutter Screen Widget and Cost Estimator
Estimate the number of widgets in a screen and a rough development-hour figure from your component counts. Adjust the fields to see how each UI area affects the total effort.
Editor and Flutter contributor
Writes practical Flutter tutorials focused on widgets, layout and animation. Enjoys breaking large UI problems into small, testable pieces and explaining them clearly to beginners.