Shimmer is an Android library that provides an easy way to add a shimmer effect to any view in your Android app. It is useful as an unobtrusive loading indicator that was originally developed for Facebook Home.
Shimmer for Android is implemented as a layout, which means that you can simply
nest any view inside a
ShimmerFrameLayout tag, and call to start
the animation from your code. That's all that is required. The layout will use the
values you specify either on the tag (using custom attributes) or programmatically
in your code, and generate an animation on the fly. See the
API reference for further details.
Here's an example of a composite view, consisting of an image and some text below it, that shows the effect in action:
To include Shimmer in your project, add the following dependency:
Note that you cannot use the custom attributes on the tag if you use the Jar file. You can instead download the AAR file and reference that locally in your project.
You can use the included Gradle wrapper to build the Shimmer library and sample application locally as well. Check out the code at github.com/facebook/shimmer-android.
The following snippet shows how you can use
In your code, you can then start the animation:
You can control the look and pace of the effect using a number of custom
attributes on the
ShimmerFrameLayout tag. Alternatively, you
can set these values on the layout object itself. For a comprehensive list,
check out the API reference
- Clip to Children
- Whether to clip the shimmering effect to the children, or to opaquely draw the shimmer on top of the children. Use this if your overall layout contains transparency.
- Whether you want the shimmer to affect just the alpha or draw colors on-top of the children.
- Base Color
- If colored is specified, the base color of the content.
- Highlight Color
- If colored is specified, the shimmer's highlight color.
- Base Alpha
- If colored is not specified, the alpha used to render the base view i.e. the unhighlighted view over which the highlight is drawn.
- Highlight Alpha
- If colored is not specified, the alpha of the shimmer highlight.
- Auto Start
- Whether to automatically start the animation when the view is shown, or not.
- Time it takes for the highlight to move from one end of the layout to the other.
- Repeat Count
- Number of times of the current animation will repeat.
- Repeat Delay
- Delay after which the current animation will repeat.
- Repeat Mode
- What the animation should do after reaching the end, either restart from the beginning or reverse back towards it.
- The travel direction of the shimmer highlight: left to right, top to bottom, right to left or bottom to top.
- Controls the size of the fading edge of the highlight.
- Controls the brightness of the highlight at the center
- Shape of the highlight mask, either with a linear or a circular gradient.
- Angle at which the highlight is tilted, measured in degrees
- Fixed Width, Height
- Fixed sized highlight mask, if set, overrides the relative size value
- Width, Height ratio
- Size of the highlight mask, relative to the layout it is applied to.
Join the discussion over at our Facebook Group to report bugs, request features or show off your project.
Open an issue on Github if you are using this component in production and would like to be added to this list.
Slingshot uses Shimmer for Android to indicate loading status.
Facebook Home uses the Shimmer effect to indicate status while loading the news feed, notifications and wallpaper settings.
For Shimmer software
Copyright (c) 2015, Facebook, Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.