Android Development--facebook cool Open Source Library shimmer use

Source: Internet
Author: User
<span id="Label3"></p><p><p>Today on the Internet when inadvertently saw the Facebook Shimmer Open source library, It is very cool, and the use of ultra-convenient, decided to introduce YOU. Shimmer is a java-based library provided by Facebook that makes all view controls in Android have a shiny effect. The Project's GitHub project hosting address, please poke https://github.com/facebook/shimmer-android</p></p>Using Shimmer to configure engineering <ol> <ol> <li>first, We clone the project locally on github;</li> <li>Next we import the required module in Android studio, i.e. shimmer-android;</li> <li>finally, you need to configure your own gradle to reference the Module:</li> </ol> </ol><pre class="prettyprint"><pre class="prettyprint"><code class=" hljs scss">dependencies { <span class="hljs-function">project(<span class="hljs-string">‘:shimmer-android‘</span>)</span>}</code></pre></pre>Add to Layout file<p><p>Shimmerframelayout is the class we need to use, and it inherits from the layout of android, which means that we can nest our own layout controls inside the layout to achieve the effect of flash, simple and Convenient.</p></p><pre class="prettyprint"><code class=" hljs avrasm"><<span class="hljs-keyword"><span class="hljs-keyword">com</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. Facebook</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. Shimmer</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. Shimmerframelayout</span></span>Android:id=<span class="hljs-string"><span class="hljs-string">"@+id/shimmercontent"</span></span>Android:layout_width=<span class="hljs-string"><span class="hljs-string">"match_parent"</span></span>android:layout_height=<span class="hljs-string"><span class="hljs-string">"match_parent"</span></span>> <textview android:text=<span class="hljs-string"><span class="hljs-string">"@string/hello_world"</span></span>Android:layout_width=<span class="hljs-string"><span class="hljs-string">"wrap_content"</span></span>Android:textsize=<span class="hljs-string"><span class="hljs-string">"40sp"</span></span>Android:textcolor=<span class="hljs-string"><span class="hljs-string">"#fff"</span></span>android:layout_gravity=<span class="hljs-string"><span class="hljs-string">"center"</span></span>android:layout_height=<span class="hljs-string"><span class="hljs-string">"wrap_content"</span></span>/></<span class="hljs-keyword"><span class="hljs-keyword">com</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. Facebook</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. Shimmer</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. Shimmerframelayout</span></span>></code></pre>Start animation<p><p>Get the layout shimmerframelayout in the activity and call its startshimmeranimation method, we can see the flash effect.</p></p><pre class="prettyprint"><pre class="prettyprint"><code class=" hljs avrasm">ShimmerFrameLayout shimmerFrameLayout = (ShimmerFrameLayout) findViewById(R<span class="hljs-preprocessor">.id</span><span class="hljs-preprocessor">.shimmerContent</span>)<span class="hljs-comment">;</span>shimmerFrameLayout<span class="hljs-preprocessor">.startShimmerAnimation</span>()<span class="hljs-comment">;</span></code></pre></pre><p><p>The effect is as Follows:<br></p></p>Customize your own Flash effect<p><p>Facebook provides several ways for this class to allow us to customize our own Flash effects, as described in the API documentation http://facebook.github.io/shimmer-android/javadoc/index.html</p></p>Set Animation time interval<p><p>The Setduration method allows us to pass an int value to set the time interval of the animation in milliseconds</p></p>Set Animation repetition type<p><p>The Setrepeatmode method under Shimmerframelayout allows us to set the repeating mode of the animation, there are two kinds of<br>Reverse or restart,reverse indicates that the flash is from left to right and then reciprocating from right to left, while restart indicates that the flash always goes from left to Right.<br>For a more visual explanation, we add in the code,</p></p><pre class="prettyprint"><pre class="prettyprint"><code class=" hljs avrasm">shimmerFrameLayout<span class="hljs-preprocessor">.setRepeatMode</span>(ObjectAnimator<span class="hljs-preprocessor">.REVERSE</span>)<span class="hljs-comment">;</span></code></pre></pre><p><p>You can see the following effects:</p></p><p><p></p></p>Set the tilt angle of the Flash<p><p>The Settilt method allows us to set the tilt angle of the light, the incoming parameter is the float type, represents the angle of the skew, positive value indicates a clockwise tilt, and a negative value indicates a counterclockwise Tilt.<br>The Setangle method is not so much about setting the angle as setting the direction, because the Method's incoming parameters can only be set to one of the following four types,<br>ShimmerFrameLayout.MaskAngle.CW_0 indicates a left-to-right direction<br>ShimmerFrameLayout.MaskAngle.CW_90 indicates the direction from top to bottom<br>ShimmerFrameLayout.MaskAngle.CW_180 represents a right-to-left direction ShimmerFrameLayout.MaskAngle.CW_270 represents the bottom-to-top direction</p></p>Set the width of the light<p><p>The Setdropoff method sets the width of the light, which represents a relative width, which represents the proportions of the entire shimmerframelayout Width. Even if setting this value to 0.5f indicates that the width of the light is half the Shimmerframelayout.</p></p>Set transparency<p><p>The Setbasealpha method allows us to set the transparency of places without Illumination.<br>Setintensity sets the intensity of the light, which, according to the test, should be the transparency of the edge part of the Light.</p></p>Set the shape of the light<p><p>The Setmaskshape method allows us to set the shape of the light, can now be set to linear ShimmerFrameLayout.MaskShape.LINEAR (default), circular or radial ShimmerFrameLayout.MaskShape.RADIAL</p></p> <p><p>Android Development--facebook cool Open Source Library shimmer use</p></p></span>

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.