Android Animation Introduction-tween Animation

Source: Internet
Author: User

3.0 ago, Android supports two animation modes,Tween animation,frame Animation
In android3.0, a new animation system was introduced: propertyAnimation
These three animation modes are called Property Animation,view animation,drawable in the SDK Animation
The following describes: Tween Animation
View Animation (Tween Animation): Motion tween, gives two keyframes, with some algorithms to ramp a given attribute value between two keyframes in a given time.
Provides effects such as rotate, move, scale, pan, and so on, you can use XML to build animations, or you can use code to build animations
XML-built animations: Creating XML files in Res/anim, using nodes with:<alpha>,<scale>,<translate>,<rotate>
Can be used to put the animation effect into the collection, can produce a different effect, the default is to execute simultaneously,
You can also use the Startoffset property to specify the delay execution time of the animation so that the effect can be performed separately

The following is an example of the XML build code:

Alpha.xml

<set xmlns:android= "Http://schemas.android.com/apk/res/android" >    <alpha        android:duration= "1000 "        android:fillafter=" false "        android:fromalpha=" 1.0 "        android:toalpha=" 0 ">    </alpha>< /set>
Rotate.xml

<set xmlns:android= "Http://schemas.android.com/apk/res/android" >    <rotate        android:duration= " "        android:fillafter=" false "        android:fromdegrees=" 0 "        android:pivotx=" 0.5 "        android: pivoty= "0.5"        android:todegrees= ">"    </rotate></set>

Scale.xml

<set xmlns:android= "Http://schemas.android.com/apk/res/android" >    <scale        android:duration= "1000 "        android:fillafter=" false "        android:fromxscale=" 1.0 "        android:fromyscale=" 1.0 "        Android:toxscale = "0"        android:toyscale= "0" >    </scale></set>

Translate.xml

<?xml version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "Http://schemas.android.com/apk/res/android" >    <translate        android:duration= "android:fillafter="        false "        android:fromxdelta=" 0 "        android:fromydelta= "0"        android:toxdelta= "Android:toydelta="        /></set>

Set.xml

<?xml version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "Http://schemas.android.com/apk/res/android" > <alpha android:duration= "" android:fillafter= "false" android:fromalpha= "1.0" an        Droid:toalpha= "0.5" > </alpha> <scale android:duration= "$" android:fillafter= "false" Android:fromxscale= "1.0" android:fromyscale= "1.0" android:startoffset= "" android:toxscale= "0 .5 "android:toyscale=" 0.5 "> </scale> <rotate android:duration=" Android:filla " Fter= "false" android:fromdegrees= "0" android:pivotx= "0.5" android:pivoty= "0.5" android:startof        fset= "android:todegrees=" > </rotate> <translate android:duration= "1000"        Android:fillafter= "false" Android:fromxdelta= "0" android:fromydelta= "0" android:startoffset= "3000"        Android:toxdelta= "200"Android:toydelta= "/></set>" 

How to use:

Activity_tween.xml

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Match_parent "android:layout_height=" match_parent "android:orientation=" vertical " > <button android:id= "@+id/alpha" android:layout_width= "Match_parent" android:layout_height= "Wrap_content" android:layout_margin= "3DP" android:gravity= "center" android:text= "Alpha" Andro Id:textsize= "20sp"/> <button android:id= "@+id/scale" android:layout_width= "Match_parent" an droid:layout_height= "Wrap_content" android:layout_margin= "3DP" android:gravity= "center" android:text= "Scale" android:textsize= "20sp"/> <button android:id= "@+id/rotate" Android:layout_width= "Ma         Tch_parent "android:layout_height=" wrap_content "android:layout_margin=" 3DP "android:gravity=" center "      android:text= "Rotate"  Android:textsize= "20sp"/> <button android:id= "@+id/translate" android:layout_width= "match_parent "Android:layout_height=" wrap_content "android:layout_margin=" 3DP "android:gravity=" center "an droid:text= "Translate" android:textsize= "20sp"/> <button android:id= "@+id/set" Android:layo Ut_width= "Match_parent" android:layout_height= "wrap_content" android:layout_margin= "3DP" Android:grav ity= "Center" android:text= "set" android:textsize= "20sp"/> <imageview android:id= "@+id/targe T "android:layout_width=" match_parent "android:layout_height=" Wrap_content "android:layout_gravity=" C Lip_horizontal "android:layout_margin=" 30DP "android:src=" @drawable/image "/></linearlayout>


Tweenactivity.java

public class Tweenactivity extends Activity implements Onclicklistener {Private button Alpha;private button scale;private button rotate;private button translate;private button set;private ImageView target; @Overrideprotected void OnCreate ( Bundle savedinstancestate) {//TODO auto-generated method Stubsuper.oncreate (savedinstancestate); Setcontentview ( R.layout.activity_tween); Initview (); Setlistener ();} private void Initview () {alpha = (button) Findviewbyid (r.id.alpha); scale = (button) Findviewbyid (r.id.scale); rotate = (Bu Tton) Findviewbyid (r.id.rotate); translate = (Button) Findviewbyid (r.id.translate); set = (Button) Findviewbyid ( R.id.set); target = (ImageView) Findviewbyid (r.id.target);} private void Setlistener () {Alpha.setonclicklistener (this), Scale.setonclicklistener (this); Rotate.setonclicklistener (This), Translate.setonclicklistener (This), Set.setonclicklistener (this); Target.setonclicklistener (this);} @Overridepublic void OnClick (View v) {switch (V.getid ()) {case r.id.alpha:startanimation (R).Anim.alpha); break;case r.id.scale:startanimation (R.anim.scale); Break;case r.id.rotate:startanimation ( r.anim.rotate); break;case r.id.translate:startanimation (r.anim.translate); Break;case R.id.set:startAnimation ( R.anim.set); break;default:break;}} public void startanimation (int animaxml) {Animation Animation = animationutils.loadanimation (Getapplicationcontext (), Animaxml); target.startanimation (animation);}}

get animation:animation Animation = Animationutils.loadanimation (Getapplicationcontext (), animaxml);

Animate view: Target.startanimation (animation);


XML File Build Animation

Reference: http://blog.csdn.net/forwardyzk/article/details/42266015

Code-building animations:

Reference: http://blog.csdn.net/forwardyzk/article/details/42387247

:



Android Animation Introduction-tween Animation

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.