Android XML Implementation Animation 4 kinds of animation effects instance Code _android

Source: Internet
Author: User

Animation has four types of animation: Alpha (transparent gradient), rotate (rotation), scale (size scaling), translate (move), two implementations of distribution, one is Javacode, the other is XML, And what I'm going to say today is the XML implementation method, the personal feeling Javacode implementation method is simpler than the XML, therefore has the need to be possible to look for the data to see for oneself.

First to show you the effect of the picture, if you feel good, please continue to read down.

Here are my four XML files that represent the four types of animation.

Alpha.xml

COde:

<?xml version= "1.0" encoding= "UTF-8"?> <set xmlns:android=
"http://schemas.android.com/apk/res/" Android "
android:interpolator=" @android: Anim/accelerate_interpolator ">
<!--gradient transparent animation effect-->
<!--fromalpha Animation start transparent 1.0 completely opaque
toalpha 0.0 full transparent at the end of animation
Startoffset set startup time
Duration Property animation Duration
-- >
<alpha 
android:fromalpha= "1.0"
android:toalpha= "0.0"
android:startoffset= "500"
android:duration= "5000"
/>
</set>

Rotate.xml

<?xml version= "1.0" encoding= "UTF-8"?> <set xmlns:android=
"http://schemas.android.com/apk/res/" Android "
android:interpolator=" @android: Anim/accelerate_interpolator ">
<!--picture Transfer rotation animation effect-->
<!--
fromdegrees start angle
todegrees End Angle
pivotx set the x axis coordinates when rotating
-->
<rotate 
android: fromdegrees= "0"
android:todegrees= "+360"
android:pivotx= "50%"
android:pivoty= "50%"
Android :d uration= "5000"
/>
</set>

Scale.xml

<?xml version= "1.0" encoding= "UTF-8"?> <set xmlns:android=
"http://schemas.android.com/apk/res/" Android "
android:interpolator=" @android: Anim/accelerate_interpolator ">
<!--gradient size telescopic animation effect-->
<!--
fromxscale start x coordinate
toxscale x axis coordinate
fromyscale start y coordinate
toyscale y axis coordinate
pivotx set x axis coordinates at rotation
Pivoty Set the y-coordinate
duration duration of rotation
-->
<scale 
android:fromxscale= "1.0"
Android : toxscale= "0.0"
android:fromyscale= "1.0" android:toyscale= "0.0"
android:pivotx= "
50%" Android:pivoty= "50%"
android:duration= "5000"
/>
</set>

Translate.xml

<?xml version= "1.0" encoding= "UTF-8"?> <set xmlns:android=
"http://schemas.android.com/apk/res/" Android "
android:interpolator=" @android: Anim/accelerate_interpolator ">
<!--picture Transfer position move animation effect-->
<translate 
android:fromxdelta= "0%"
android:toxdelta= "
100%" Android:fromydelta= "0%" Android:toydelta= "0%"
android:duration= "5000" 
/>
</set>

The following is the layout of the main interface 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:o" rientation= "vertical" >
<imageview 
android:id= "@+id/image1" android:layout_width= "Match_"
Parent "
android:layout_height=" 200px "
/>
<imageview 
android:id=" @+id/image2
" Android:layout_width= "Match_parent"
android:layout_height= "200px"
/>
<imageview 
Android:id= "@+id/image3"
android:layout_width= "match_parent"
android:layout_height= "200px"
/ >
<imageview 
android:id= "@+id/image4"
android:layout_width= "Match_parent"
android: layout_height= "200px"
/>
</LinearLayout>

And then the activity code.

public class Animationdemo extends activity{private Animation animation,animation1,animation2,animation3; private
ImageView Image1,image2,image3,image4; @Override protected void OnCreate (Bundle savedinstancestate) {//TODO auto-generated Method stub super.oncreate (savedins
Tancestate);
Setcontentview (r.layout.animation);
Initview (); public void Initview () {animation=animationutils.loadanimation (animationdemo.this, r.anim.rotate); animation1=
Animationutils.loadanimation (Animationdemo.this, R.anim.scale);
Animation2=animationutils.loadanimation (Animationdemo.this, R.anim.alpha);
Animation3=animationutils.loadanimation (Animationdemo.this, r.anim.translate);
image1= (ImageView) Findviewbyid (r.id.image1);
Image1.setimageresource (R.drawable.jpeg);
Image2= (ImageView) Findviewbyid (r.id.image2);
Image2.setimageresource (r.drawable.jpg);
image3= (ImageView) Findviewbyid (R.ID.IMAGE3);
Image3.setimageresource (r.drawable.png);
image4= (ImageView) Findviewbyid (r.id.image4); Image4.setimageresource (r.drAwable.gif);
Image1.startanimation (animation);
Image2.startanimation (Animation1);
Image3.startanimation (Animation2);
Image4.startanimation (Animation3); }
}

Well, this is the first four kinds of animation effect, there is also a knowledge point, is the speed of the animation inside the problem, there is a need to go online Baidu to see it.


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.