Android Development _ talking about the animation (four)

Source: Internet
Author: User
<span id="Label3"></p><p><p><span style="line-height: 1.5;">Property animation</span></p></p><p><p>Concept: Property animation, that is, by changing the object properties of the Animation.</p></p><p><p>Features: Property Animations really change the location of a UI control, including its event trigger focus</p></p><p><p></p></p><p><p></p></p><p><p>first, the important animation class and the attribute Value:</p></p><p><p>1. Valueanimator Basic Properties Animation class</p></p><p><p></p></p> <table border="1" cellspacing="0" cellpadding="0"> <tbody> <tr> <td valign="top" width="446"><p>Method</p></td> <td valign="top" width="94"><p>Describe</p></td> </tr> <tr> <td valign="top" width="446"><p>Setduration (long Duration)</p></td> <td valign="top" width="94"><p>How to set the duration of an animation</p></td> </tr> <tr> <td valign="top" width="446"><p>Setevaluator (typeevaluator Value)</p></td> <td valign="top" width="94"><p>Set the type of interpolation calculation</p></td> </tr> <tr> <td valign="top" width="446"><p>Setinterpolator (timeinterpolator Value)</p></td> <td valign="top" width="94"><p>Set the type of the time Interpolator</p></td> </tr> <tr> <td valign="top" width="446"><p>Addupdatelistener (valueanimator.animatorupdatelistener Listener)</p></td> <td valign="top" width="94"><p>Update listener events for animated objects</p></td> </tr> <tr> <td valign="top" width="446"><p>Setrepeatcount (int Value)</p></td> <td valign="top" width="94"><p>Set the number of times an animation repeats execution</p></td> </tr> <tr> <td valign="top" width="446"><p>Setrepeatmode (int Value)</p></td> <td valign="top" width="94"><p>Set Animation repeat mode</p></td> </tr> <tr> <td valign="top" width="446"><p>AddListener (animator.animatorlistener L)</p></td> <td valign="top" width="94"><p>Setting Up Listener Events</p><p>Yes</p><p>1. Listening at the beginning of the animation</p><p>2. Listening at the end of the animation</p><p>3. Listening when the animation starts again</p></td> </tr> <tr> <td valign="top" width="446"><p>Start ()</p></td> <td valign="top" width="94"><p>Start the animation execution</p></td> </tr> <tr> <td valign="top" width="446"><p>Cancel ()</p></td> <td valign="top" width="94"><p>Stops the currently executing animation, and the property value stops at the current execution position</p></td> </tr> <tr> <td valign="top" width="446"><p>End ()</p></td> <td valign="top" width="94"><p>Ends the animation, the property value stops at the end position, even if the animation is not finished playing</p></td> </tr> </tbody> </table><p><p></p></p><p><p>2, Objectanimator object property animation class, inherit from Valueanimator</p></p> <table border="1" cellspacing="0" cellpadding="0"> <tbody> <tr> <td valign="top" width="276"> <p> method </p> </td> <td valign="top" width="269"> <p> Description </p> </td> </tr> <tr> TD valign= "top" width= "276" > <td valign="top" width="269"> <p> The first parameter is an object that performs Animation. The second value is a property, followed by an indeterminate number of change values for the float type </p> </td> </tr> <ul> <li> offloat (T target, property<t, float> property, Float ... values) </li> </ul> <tr> <td valign="top" width="276"> <ul> <li> ofint (T target, prope rty<t, integer> property, int ... Values) </li> </ul> </td> <td valign="top" width="269"> <p> The first argument is an object that performs Animation. The second value is the property, followed by the variable value of an indeterminate number of int types </p> </td> </tr> <tr> <td valign="top" width="276"> <ul> <li> Ofobject (Object target, String propertyname, typeevaluator evaluator, Object ... values) </li> </ul> </td> <td valign="top" width="269"> <p> First parameter The number is the object that performs the Animation. The second value is a property, followed by a variable value of an indeterminate number of type Object </p> </td> </tr> <tr> <td valign="top" width="276"> <p> settarget (object Target) </p> </td> <td valign="top" width="269" "> <p> Set the object that performs the animation </p> </td> </tr> </tbody> </table><p><p></p></p><p><p></p></p><p><p>3. Timeinterpolator time interpolation device</p></p><p><p>Set the action effect for animation execution</p></p><p><p>Eg:animator.setInterpolator (<strong>new</strong> bounceinterpolator ()//set animation effect to jump</p></p> <table border="1" cellspacing="0" cellpadding="0"> <tbody> <tr> <td valign="top" width="284"><p>Type</p></td> <td valign="top" width="261"><p>Describe</p></td> </tr> <tr> <td valign="top" width="284"><p>Accelerateinterpolator</p></td> <td valign="top" width="261"><p>acceleration, Slow intermediate acceleration at start</p></td> </tr> <tr> <td valign="top" width="284"><p>Decelerateinterpolator</p></td> <td valign="top" width="261"><p>Slow down, start fast, then slow down.</p></td> </tr> <tr> <td valign="top" width="284"><p>Acceleratedecelerateinterolator</p></td> <td valign="top" width="261"><p>Acceleration and deceleration, slow start, middle acceleration</p></td> </tr> <tr> <td valign="top" width="284"><p>Anticipateinterpolator</p></td> <td valign="top" width="261"><p>reverse, change a paragraph in the opposite direction and then accelerate the playback</p></td> </tr> <tr> <td valign="top" width="284"><p>Anticipateovershootinterpolator</p></td> <td valign="top" width="261"><p>Reverse addition, first change in the opposite direction, and then accelerate the play, will exceed the target value and then move slowly to the destination value</p></td> </tr> <tr> <td valign="top" width="284"><p>Bounceinterpolator</p></td> <td valign="top" width="261"><p>jump, fast to the destination value will jump, such as the destination value 100, The following value may be followed by 85,77,70,80,90,100</p></td> </tr> <tr> <td valign="top" width="284"><p>Cycleiinterpolator</p></td> <td valign="top" width="261"><p>loop, Animation cycle A certain number of times, the value is changed to a sine function: math.sin (2 * Mcycles * Math.PI * input)</p></td> </tr> <tr> <td valign="top" width="284"><p>Linearinterpolator</p></td> <td valign="top" width="261"><p>linear, Linear Uniform Change</p></td> </tr> <tr> <td valign="top" width="284"><p>Overshottinterpolator</p></td> <td valign="top" width="261"><p>exceed, and then slowly change to the destination value</p></td> </tr> </tbody> </table><p><p></p></p><p><p>4, Propertyvaluesholder</p></p><p><p>Action: performs multiple property animations on a view that optimizes multi-attribute animations and merges some invalidate () to reduce the refresh view, which is introduced in 3.1</p></p><p><p></p></p><p><p>5. Type of typeevaluator interpolation calculation</p></p><p><p>(1), intevaluator: The value type of the property is int</p></p><p><p>(2), floatevaluator: The value type of the property is float</p></p><p><p>(3), argbevaluator: The value type of the property is a hexadecimal color value</p></p><p><p></p></p><p><p>6. Common Animation Properties</p></p><p><p>(1) translationx,translationy: Moving coordinates</p></p><p><p>(2) rotation,rotationx,rotationy: rotation, rotation for 2D rotation angle, 3D for the latter two</p></p><p><p>(3) scalex,scaley: Zoom</p></p><p><p>(4) Alpha: Transparency</p></p><p><p>(5) backgroundcolor: Background</p></p><p><p></p></p><p><p>second, the animation demo</p></p><p><p>1, Displacement Animation</p></p><pre><span style="color: #008080;"><span style="color: #008080;">1</span></span>Valueanimator animator = Objectanimator.offloat (image,<span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #800000;"><span style="color: #800000;">Translationy</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span>,<span style="color: #800080;"><span style="color: #800080;"></span> -</span><span style="color: #000000;"><span style="color: #000000;">);//the First argument is an animated object ImageView The second argument is an animated property: y-axis displacement, and the third parameter is value</span></span><span style="color: #008080;"><span style="color: #008080;">2</span></span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">events performed by animations</span></span><span style="color: #008080;"><span style="color: #008080;">3</span></span>Animator.setduration (<span style="color: #800080;"><span style="color: #800080;"></span> the</span><span style="color: #000000;"><span style="color: #000000;">);</span></span><span style="color: #008080;"><span style="color: #008080;">4</span></span> <span style="color: #000000;"><span style="color: #000000;">Animator.setrepeatcount (valueanimator.infinite);//set The number of Cycles: unlimited</span></span><span style="color: #008080;"><span style="color: #008080;">5</span></span> <span style="color: #000000;"><span style="color: #000000;">Animator.setrepeatmode (valueanimator.reverse); Set Loop mode: Flashback Loop</span></span><span style="color: #008080;"><span style="color: #008080;">6</span></span> <span style="color: #008080;"><span style="color: #008080;">7</span></span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">set the acceleration effect</span></span><span style="color: #008080;"><span style="color: #008080;">8</span></span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">animator.setinterpolator (new acceleratedecelerateinterpolator ());</span></span><span style="color: #008080;"><span style="color: #008080;">9</span></span>Animator.setinterpolator (<span style="color: #0000ff;"><span style="color: #0000ff;">New</span></span><span style="color: #000000;"><span style="color: #000000;">Bounceinterpolator ()); Set Bounce Effect</span></span><span style="color: #008080;"><span style="color: #008080;">Ten</span></span>Animator.start ();</pre><p><p>Effect:</p></p><p><p></p></p><p><p>2. Rotate the animation around the x-axis</p></p><pre><pre><span style="color: #008080;">1</span> <span style="color: #800000;">"</span> <span style="color: #800000;">RotationX</span> <span style="color: #800000;">"</span> <span style="color: #800080;">0</span>,<span style="color: #800080;">720</span><span style="color: #000000;"><br></span><span style="color: #008080;">2</span> Animator.setduration (<span style="color: #800080;">4000</span><span style="color: #000000;">);</span> <span style="color: #008080;">3</span> <span style="color: #000000;"> animator.setrepeatcount (valueanimator.infinite);</span> <span style="color: #008080;">4</span> <span style="color: #000000;"> Animator.setrepeatmode (valueanimator.reverse);</span> <span style="color: #008080;">5</span> Animator.start ();</pre></pre><p><p>:</p></p><p><p></p></p><p><p></p></p><p><p>3, the picture around the XY axis rotation, two properties action case</p></p><pre><span style="color: #008080;"><span style="color: #008080;">1</span></span>Propertyvaluesholder pvh1 = Propertyvaluesholder.offloat (<span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #800000;"><span style="color: #800000;">RotationY</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">, 0f,45f,90f,160f,260f,360f);</span></span><span style="color: #008080;"><span style="color: #008080;">2</span></span>Propertyvaluesholder PVH2 = Propertyvaluesholder.offloat (<span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #800000;"><span style="color: #800000;">RotationX</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">, 0f,360f);</span></span><span style="color: #008080;"><span style="color: #008080;">3</span></span> <span style="color: #008080;"><span style="color: #008080;">4</span></span>Valueanimator animator =<span style="color: #000000;"><span style="color: #000000;">Objectanimator.ofpropertyvaluesholder (image,pvh1,pvh2);//merge Multiple animations that need to be executed concurrently</span></span><span style="color: #008080;"><span style="color: #008080;">5</span></span>Animator.setduration (<span style="color: #800080;"><span style="color: #800080;">4000</span></span><span style="color: #000000;"><span style="color: #000000;">);</span></span><span style="color: #008080;"><span style="color: #008080;">6</span></span> <span style="color: #000000;"><span style="color: #000000;">Animator.setrepeatcount (valueanimator.infinite);</span></span><span style="color: #008080;"><span style="color: #008080;">7</span></span> <span style="color: #000000;"><span style="color: #000000;">Animator.setrepeatmode (valueanimator.reverse);</span></span><span style="color: #008080;"><span style="color: #008080;">8</span></span>Animator.start ();</pre><p><p>:</p></p><p><p></p></p><p><p>4. The case of multiple property animations executed together</p></p><pre><span style="color: #008080;"><span style="color: #008080;">1</span></span>Animatorset ASet =<span style="color: #0000ff;"><span style="color: #0000ff;">New</span></span><span style="color: #000000;"><span style="color: #000000;">Animatorset ();</span></span><span style="color: #008080;"><span style="color: #008080;">2</span></span>Valueanimator A1 =<span style="color: #000000;"><span style="color: #000000;">objectanimator.offloat (image, "translationx", 0f,200f);</span></span><span style="color: #008080;"><span style="color: #008080;">3</span></span>A1.setduration (<span style="color: #800080;"><span style="color: #800080;"></span> -</span><span style="color: #000000;"><span style="color: #000000;">);</span></span><span style="color: #008080;"><span style="color: #008080;">4</span></span> <span style="color: #008080;"><span style="color: #008080;">5</span></span>Valueanimator A2 = Objectanimator.offloat (1f,<span style="color: #800080;"><span style="color: #800080;">1.5f</span></span>,<span style="color: #800080;"><span style="color: #800080;">1.0f</span></span><span style="color: #000000;"><span style="color: #000000;">);</span></span><span style="color: #008080;"><span style="color: #008080;">6</span></span>A2.addupdatelistener (<span style="color: #0000ff;"><span style="color: #0000ff;">New</span></span><span style="color: #000000;"><span style="color: #000000;">Animatorupdatelistener () {</span></span><span style="color: #008080;"><span style="color: #008080;">7</span></span> <span style="color: #008080;"><span style="color: #008080;">8</span></span> <span style="color: #000000;"><span style="color: #000000;">@Override</span></span><span style="color: #008080;"><span style="color: #008080;">9</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;"></span> public</span> <span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span><span style="color: #000000;"><span style="color: #000000;">onanimationupdate (valueanimator Animation) {</span></span><span style="color: #008080;"><span style="color: #008080;">Ten</span></span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">TODO auto-generated Method Stub</span></span><span style="color: #008080;"><span style="color: #008080;"></span> one</span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">methods for updating the properties of an object</span></span><span style="color: #008080;"><span style="color: #008080;"></span> a</span> <span style="color: #0000ff;"><span style="color: #0000ff;">float</span></span>Value =<span style="color: #000000;"><span style="color: #000000;">(Float) animation.getanimatedvalue ();</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #000000;"><span style="color: #000000;">Image.setscalex (value);</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #000000;"><span style="color: #000000;">Image.setscaley (value);</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #000000;"><span style="color: #000000;"> }</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #000000;"><span style="color: #000000;"> });</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span>A2.setduration (<span style="color: #800080;"><span style="color: #800080;"></span> +</span><span style="color: #000000;"><span style="color: #000000;">);</span></span><span style="color: #008080;"><span style="color: #008080;"></span> +</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Rotate</span></span><span style="color: #008080;"><span style="color: #008080;"></span> +</span>Valueanimator a3 = Objectanimator.offloat (image,<span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #800000;"><span style="color: #800000;">Rotation</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span>, 0f,<span style="color: #800080;"><span style="color: #800080;"></span> the</span><span style="color: #000000;"><span style="color: #000000;">);</span></span><span style="color: #008080;"><span style="color: #008080;"></span> a</span>A3.setduration (<span style="color: #800080;"><span style="color: #800080;"></span> the</span><span style="color: #000000;"><span style="color: #000000;">);</span></span><span style="color: #008080;"><span style="color: #008080;"></span> at</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Gradient</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span>Valueanimator a4 = objectanimator.offloat (image,<span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #800000;"><span style="color: #800000;">Alpha</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">, 1f,0f);</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span>A4.setduration (<span style="color: #800080;"><span style="color: #800080;"></span> +</span><span style="color: #000000;"><span style="color: #000000;">);</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #000000;"><span style="color: #000000;">aset.play (a1). with (a3);</span></span><span style="color: #008080;"><span style="color: #008080;"></span> in</span> <span style="color: #000000;"><span style="color: #000000;">aset.play (a2). after (a3);</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #000000;"><span style="color: #000000;">aset.play (a2). with (a4);</span></span><span style="color: #008080;"><span style="color: #008080;"></span> to</span> <span style="color: #008080;"><span style="color: #008080;"></span> +</span>Aset.start ();</pre><p><p></p></p><p><p>:</p></p><p><p></p></p><p><p></p></p><p><p>5. Layout Background Animation</p></p><pre><span style="color: #008080;"><span style="color: #008080;">1</span></span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">change the background of the main layout to achieve animation effects</span></span><span style="color: #008080;"><span style="color: #008080;">2</span></span>Animator = Objectanimator.ofint (linearlayout,<span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #800000;"><span style="color: #800000;">BackgroundColor</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">, color.white,color.blue,color.green,color.red);</span></span><span style="color: #008080;"><span style="color: #008080;">3</span></span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Set color worth difference type</span></span><span style="color: #008080;"><span style="color: #008080;">4</span></span>Animator.setevaluator (<span style="color: #0000ff;"><span style="color: #0000ff;">New</span></span><span style="color: #000000;"><span style="color: #000000;">Argbevaluator ());</span></span><span style="color: #008080;"><span style="color: #008080;">5</span></span>Animator.setduration (<span style="color: #800080;"><span style="color: #800080;"></span> the</span><span style="color: #000000;"><span style="color: #000000;">);</span></span><span style="color: #008080;"><span style="color: #008080;">6</span></span> <span style="color: #000000;"><span style="color: #000000;">Animator.setrepeatcount (valueanimator.infinite);</span></span><span style="color: #008080;"><span style="color: #008080;">7</span></span> <span style="color: #000000;"><span style="color: #000000;">Animator.setrepeatmode (valueanimator.reverse);</span></span><span style="color: #008080;"><span style="color: #008080;">8</span></span>Animator.start ();</pre><p><p>:</p></p><p><p></p></p><p><p></p></p><p><p>--------------------------------------------------------------------------------------------------------------- -----------------</p></p><p><p>Related knowledge:</p></p><p><p>Android Development _ Introduction</p></p><p><p>Android Development _ A brief introduction to the animation (ii)</p></p><p><p>Android Development _ A brief introduction to the animation (three)</p></p><p><p></p></p><p><p>Android Development _ talking about the animation (four)</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.