Use of android--animations (i)--tweened animations

Source: Internet
Author: User
<span id="Label3"></p><p><p>Use of animations (i)--</p></p>1. What is animation<p><p>Animations provides a series of animated effects that can be applied to most controls.</p></p><p><p>rotate, scale, Fade. Can be used in most controls,</p></p>2, the classification of animations<p><p>Generally speaking, there are two kinds of categories:</p></p><p><p><strong>First category: tweened animations <span style="color: #ff0000;">gradient animation</span></strong></p></p><p><p>This class of animations provides the effects of <span style="color: #ff0000;"><strong>rotation, movement, stretching</strong></span> , and <span style="color: #ff0000;"> <strong>fading</strong> <strong></strong> </span> .</p></p><p><p><strong>Type Ii: frame-by-frame animations</strong></p></p><p><p><span style="color: #ff0000;"><strong>Like movies, a movie is actually a collection of photos, a series of photos rolling, taking advantage of the effects of People's Visual Residue. 24/S a picture, you can think of it as Continuous.</strong></span></p></p><p><p>The class animations can create a <span style="color: #ff0000;"><strong>drawable (picture)</strong></span> sequence, which can be displayed one at a time interval, as specified by the Drawable.</p></p>Classification of tweened animations <ol> <ol> <li>Alpha Fade Effect</li> <li>Scale scaling effect</li> <li>Rotate Rotation effect</li> <li>Translate Move Effect</li> </ol> </ol>3. Steps to use tweened animations <ol> <ol> <li>Create a <span style="color: #ff0000;"><strong>animationset</strong></span> object, Set This is a collection that can put several animated objects together and can be rotated over and over again.</li> <li>Create the appropriate Animation object as needed Animation is a parent class with four subclasses representing the above</li> <li>According to the requirements of the software animation, set the corresponding data run time for the animation object, the axis</li> <li>Add the animation object to the Animationset object</li> <li>Start execution with the control object Animationset</li> </ol> </ol><p><p><strong>The use of animations, there are two major categories, one is implemented in code, a class is implemented in Xml.</strong></p></p><strong><strong>1) Alpha Effect implementation (fade In)</strong></strong><pre> <span style="color: #0000ff;"><span style="color: #0000ff;">Private</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">class</span></span>Alphabuttonlistener<span style="color: #0000ff;"><span style="color: #0000ff;">Implements</span></span><span style="color: #000000;"><span style="color: #000000;">Dialoginterface.onclicklistener {@Override</span></span><span style="color: #0000ff;"><span style="color: #0000ff;"></span> public</span> <span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span>OnClick (dialoginterface dialog,<span style="color: #0000ff;"><span style="color: #0000ff;">int</span></span><span style="color: #000000;"><span style="color: #000000;">Which) { </span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Create a Animationset object, where the Boolean parameter is set directly to True.</span></span>Animationset Animation<span style="color: #ff0000;"><span style="color: #ff0000;"><strong>Set</strong></span></span>=<span style="color: #0000ff;"><span style="color: #0000ff;">New</span></span>Animationset (<span style="color: #0000ff;"><span style="color: #0000ff;">true</span></span><span style="color: #000000;"><span style="color: #000000;">); </span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Create a alphaanimation object, where 1 means fromalpha (opaque), 0 means Toalpha (transparent)</span></span>Alphaanimation<span style="color: #ff0000;"><span style="color: #ff0000;"><strong>Alpha</strong></span></span>Animation =<span style="color: #0000ff;"><span style="color: #0000ff;">New</span></span>Alphaanimation (1, 0<span style="color: #000000;"><span style="color: #000000;">); </span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">set the time, in milliseconds, for animation execution</span></span>Alphaanimation.setduration (1000<span style="color: #000000;"><span style="color: #000000;">); </span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">to add a Alphaanimation object to the Animationset</span></span><strong><strong><span style="color: #ff0000;">animationset.addanimation (alphaanimation); </span></strong></strong><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">start an animation using the image method</span></span><span style="color: #000000;"><span style="color: #000000;">imageview.startanimation (animationset); } }</span></span></pre><p><p></p></p><p><p></p></p>2) Rotate effect (rotation Effect)<em id="__mceDel"><em id="__mceDel">   </em></em><pre> <span style="color: #0000ff;"><span style="color: #0000ff;">Private</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">class</span></span>Rotatebuttonlistener<span style="color: #0000ff;"><span style="color: #0000ff;">Implements</span></span><span style="color: #000000;"><span style="color: #000000;">Dialoginterface.onclicklistener {@Override</span></span><span style="color: #0000ff;"><span style="color: #0000ff;"></span> public</span> <span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span>OnClick (dialoginterface dialog,<span style="color: #0000ff;"><span style="color: #0000ff;">int</span></span><span style="color: #000000;"><span style="color: #000000;">Which) { </span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">rotateanimation (float fromdegrees, float todegrees,</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">int pivotxtype, float pivotxvalue,</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">int pivotytype, float Pivotyvalue)</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Fromdegrees Starting angle 0 is the 12 o'clock Direction. </span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">todegrees Termination Angle 360 is the Same. </span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">pivotxtype The coordinate type of the axis x to rotate Animation.absolute (absolute coordinates), animation.relative_to_self (coordinates relative to itself), or animation.relative_to_ Parent (coordinates relative to the parent control).</span></span>Rotateanimation rotateanimation =<span style="color: #0000ff;"><span style="color: #0000ff;">New</span></span>Rotateanimation (0, 360<span style="color: #000000;"><span style="color: #000000;">, animation.relative_to_parent,1f, animation.relative_to_parent,0f); } }</span></span></pre><p><p></p></p><p><p><strong><span style="color: #ff0000;">the next 4 parameters define the center of the rotation</span></strong> .</p></p>3) Scale Effect<pre><span style="color: #0000ff;"><span style="color: #0000ff;"></span> public</span> <span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span>OnClick (dialoginterface dialog,<span style="color: #0000ff;"><span style="color: #0000ff;">int</span></span><span style="color: #000000;"><span style="color: #000000;">Which) { </span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">8 Parameters</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;">public <span style="color: #008000;">scaleanimation (float fromX, float toX, float fromy,float toY,</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">int pivotxtype, float pivotxvalue,</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">int pivotytype, Float Pivotyvalue) {</span></span>Scaleanimation scaleanimation =<span style="color: #0000ff;"><span style="color: #0000ff;">New</span></span><span style="color: #000000;"><span style="color: #000000;">Scaleanimation (</span></span>1,0.1f,1,0.1f,<span style="color: #008000;"><span style="color: #008000;">/**</span></span><span style="color: #008000;"><span style="color: #008000;">the horizontal ordinate changes to the previous 0.1</span></span><span style="color: #008000;"><span style="color: #008000;">*/</span></span><span style="color: #000000;"><span style="color: #000000;">animation.relative_to_self,</span></span>0.5f,<span style="color: #008000;"><span style="color: #008000;">/**</span></span><span style="color: #008000;"><span style="color: #008000;">set the rotation axis for scaling</span></span><span style="color: #008000;"><span style="color: #008000;">*/</span></span><span style="color: #000000;"><span style="color: #000000;">animation.relative_to_self,</span></span>0.8f<span style="color: #000000;"><span style="color: #000000;">); }</span></span></pre><p><p><strong>4) Translate effect Implementation (mobile Effect)</strong></p></p><pre> <span style="color: #0000ff;"><span style="color: #0000ff;">Private</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">class</span></span>Translatebuttonlistener<span style="color: #0000ff;"><span style="color: #0000ff;">Implements</span></span><span style="color: #000000;"><span style="color: #000000;">Dialoginterface.onclicklistener {@Override</span></span><span style="color: #0000ff;"><span style="color: #0000ff;"></span> public</span> <span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span>OnClick (dialoginterface dialog,<span style="color: #0000ff;"><span style="color: #0000ff;">int</span></span><span style="color: #000000;"><span style="color: #000000;">Which) { </span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;">public <span style="color: #008000;">Translateanimation (</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">int fromxtype, float fromxvalue, set start position in x direction</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">int toxtype, float toxvalue, set End position in x direction</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">int fromytype, float fromyvalue, set start position in y direction</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">int toytype, Float Toyvalue) Sets the end position in the y direction</span></span>Translateanimation translateanimation =<span style="color: #0000ff;"><span style="color: #0000ff;">New</span></span><span style="color: #000000;"><span style="color: #000000;">translateanimation (animation.relative_to_self,0f, animation.relative_to_self,< /c0></span></span>0.5f<span style="color: #000000;"><span style="color: #000000;">, animation.relative_to_self,0f, animation.relative_to_self,1f); } }</span></span></pre>4. Common Properties of Animationset<p><p>There are a lot of animaition in Animationset.</p></p><pre><pre> Animationset.setduration (+); <span style="color: #008000;">//</span> <span style="color: #008000;">set time</span> for animation execution Animationset.setfillafter (<span style="color: #0000ff;">true</span>); <span style="color: #008000;">//</span> <span style="color: #008000;">after the animation finishes, stay at the end of the control state</span> Animationset.setfillbefore (<span style="color: #0000ff;">false</span>); <span style="color: #008000;">//</span> <span style="color: #008000;">when the animation is finished, stop at the start state</span> of the control Animationset.setstartoffset (+); <span style="color: #008000;">//</span> <span style="color: #008000;">set the wait time</span> before the animation executes Animationset.setrepeatcount (3); <span style="color: #008000;">//</span> <span style="color: #008000;">set the number of repeat executions for an animation</span></pre></pre><p><p></p></p><p><p></p></p><p><p></p></p><p><p>Use of android--animations (i)--tweened animations</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.