The realization of Java-android's animation

Source: Internet
Author: User

One: Show hidden animation

Create a Anim directory in the Res directory and create a alpha.xml file inside

<?xml version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "Http://schemas.android.com/apk/res/android"     android:shareinterpolator= "false"    >   <alpha     android:fromalpha= "1.0"    android:toalpha= "0"    android:duration=    ></alpha> </set>

Add a picture to the displayed page, and then in the Mainactivity.java file, get the object that needs to be animated, get an animated object that will animate the object to animate the method

Package Cn.szy.com;import Android.app.activity;import Android.os.bundle;import android.view.animation.Animation; Import Android.view.animation.animationutils;import Android.widget.imageview;public class MainActivity extends Activity {    /** called when the activity is first created. *    /@Override public    void OnCreate (Bundle Savedinstan Cestate) {        super.oncreate (savedinstancestate);        Setcontentview (r.layout.main);                Animation Animation = Animationutils.loadanimation (this, r.anim.alpha);        Animation.setfillafter (true);        ImageView ImageView = (ImageView) This.findviewbyid (r.id.imageview1);        Imageview.startanimation (animation);    }}

Two: Mobile animation

Create a Anim directory in the Res directory, then create a translate.xml file inside it and then load it in the animation.

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

Three: Rotate animation

Create a Anim directory in the Res directory, then create a rotate.xml file inside it and then load it in the animation.

<?xml version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "Http://schemas.android.com/apk/res/android"     android:shareinterpolator= "false"    ><rotate     android:fromdegrees= "0"        android: Todegrees= "android:pivotx="    50% "    android:pivoty=" 50% "android:duration="    >< /rotate>    </set>

Four: Enlarge animation

Create a Anim directory in the Res directory, then create a scale.xml file inside it and then load it in the animation.

<?xml version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "Http://schemas.android.com/apk/res/android"     android:shareinterpolator= "false" ><scale     android:fromxscale= "1.0"    android:fromyscale= "1.0"    android:toxscale= "5.0"    android:toyscale= "5.0"    android:pivotx= "50%"    android:pivoty= "50%"    android:duration= "/></set>"    

V: Set animation, the action of multiple animations written into a file, in order and time to call, you can achieve some complex animation

<?xml version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "Http://schemas.android.com/apk/res/android"     android:shareinterpolator= "false"    ><translate     android:fromxdelta= "0"    Android:fromydelta = "0"    android:toxdelta= "    android:toydelta=" "    android:duration="    ></translate >    <scale     android:fromxscale= "1.0"    android:fromyscale= "1.0"    android:toxscale= "5.0"    android:toyscale= "5.0"    android:pivotx= "50%"    android:pivoty= "50%"    android:duration= "5000"    />           <alpha            android:fromalpha= "1.0"           android:toalpha= "0"           android:duration= "5000"    /></set>

The realization of Java-android's animation

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.