Android development-use Facebook's cool open source library Shimmer and facebookshimmer

Source: Internet
Author: User

Android development-use Facebook's cool open source library Shimmer and facebookshimmer

Today, I accidentally saw Facebook's Shimmer open source library while surfing the Internet. It feels cool and convenient to use. I decided to introduce it to you. Shimmer is a Java-based library provided by Facebook. It enables all View Controls in Android to flash. GitHub project hosting address for this project, please dash the https://github.com/facebook/shimmer-android

Use Shimmer to configure the project
dependencies {       compile project(':shimmer-android')}
Add to layout File

ShimmerFrameLayout is the class we need to use. It inherits from the Layout of Android, which means that we can nest our Layout control within the Layout to achieve the flash effect, which is simple and convenient.

<com.facebook.shimmer.ShimmerFrameLayout    android:id="@+id/shimmerContent"    android:layout_width="match_parent"    android:layout_height="match_parent">    <TextView         android:text="@string/hello_world"        android:layout_width="wrap_content"        android:textSize="40sp"        android:textColor="#fff"        android:layout_gravity="center"        android:layout_height="wrap_content" /></com.facebook.shimmer.ShimmerFrameLayout>
Start Animation

Obtain the ShimmerFrameLayout layout in the Activity and call its startShimmerAnimation method. Then we can see the flash effect.

ShimmerFrameLayout shimmerFrameLayout = (ShimmerFrameLayout) findViewById(R.id.shimmerContent);shimmerFrameLayout.startShimmerAnimation();

The effect is as follows:

Customize your own flash effect

Facebook offers several ways for this class to allow us to customize our own flash effects, see the http://facebook.github.io/shimmer-android/javadoc/index.html for API documentation

Set animation Interval

The setDuration method allows us to input an int value to set the animation interval, in milliseconds.

Set the animation repetition type

The setRepeatMode method under ShimmerFrameLayout allows us to set the animation repetition mode.
REVERSE or RESTART, REVERSE indicates that the flash is from left to right, and then reciprocating from right to left. RESTART indicates that the flash is always from left to right.
To better illustrate the image, we add in the code,

shimmerFrameLayout.setRepeatMode(ObjectAnimator.REVERSE);

You can see the following results:

Set the tilt angle of the flash.

The setTilt method allows us to set the skew angle of light. The input parameter is of the float type, indicating the skew angle. A positive value indicates the clockwise skew, and a negative value indicates the clockwise skew.
The setAngle method is not so much a set direction as a set direction, because the input parameters of this method can only be set to one of the following four types,
ShimmerFrameLayout. MaskAngle. CW_0 indicates the left-to-right direction.
ShimmerFrameLayout. MaskAngle. CW_90 indicates the direction from top to bottom.
ShimmerFrameLayout. MaskAngle. CW_180 indicates the direction from right to left. ShimmerFrameLayout. MaskAngle. CW_270 indicates the direction from bottom to top.

Set the light width

The setDropoff method can set the width of the light. This value indicates a relative width, that is, the ratio of the ShimmerFrameLayout width. If this value is set to F, the light width is half of ShimmerFrameLayout.

Set transparency

The setBaseAlpha method allows us to set the transparency of a place without illumination.
SetIntensity sets the light intensity. According to the test, it should be the transparency of the edge part of the illumination.

Set the light shape

The setMaskShape method allows us to set the shape of light. Currently, it can be set to LINEAR ShimmerFrameLayout. MaskShape. LINEAR (default), circular, or RADIAL ShimmerFrameLayout. MaskShape. RADIAL.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.