Описание тега shimmer
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.
The following snippet shows how you can use ShimmerFrameLayout
<com.facebook.shimmer.ShimmerFrameLayout
android:id="@+id/shimmer_view_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
...(your complex view here)...
</com.facebook.shimmer.ShimmerFrameLayout>
And thats it! If you specify auto-start
to be false, then you can start the animation in code:
ShimmerFrameLayout container =
(ShimmerFrameLayout) findViewById(R.id.shimmer_view_container);
container.startShimmer(); // If auto-start is set to false
Attributes
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.
Colored
- 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.
Duration
- 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.
Direction
- The travel direction of the shimmer highlight: left to right, top to bottom, right to left or bottom to top.
Dropoff
- Controls the size of the fading edge of the highlight.
Intensity
- Controls the brightness of the highlight at the center.
Shape
- Shape of the highlight mask, either with a linear or a circular gradient.
Tilt
- 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.
Download
To include Shimmer in your android project, add the following dependency:
// Gradle dependency on Shimmer for Android
dependencies {
implementation 'com.facebook.shimmer:shimmer:x.x.x'
}
//Replace xxx with version
<!-- Maven dependency on Shimmer for Android -->
<dependency>
<groupId>com.facebook.shimmer</groupId>
<artifactId>shimmer</artifactId>
<version>x.x.x</version>
</dependency>
//Replace xxx with version
Обратите внимание, что вы не можете использовать настраиваемые атрибуты тега, если используете файл Jar. Вместо этого вы можете загрузить файл AAR и ссылаться на него локально в своем проекте.