Android xml implements four animation effects: androidanimation

Source: Internet
Author: User

Android xml implements four animation effects: androidanimation

Animation has four types of animation: alpha (transparent gradient), rotate (rotation), scale (size scaling), and translate (movement). There are two types of animation distribution, one is javaCode and the other is XML. What I want to talk about today is the XML implementation method. I personally feel that the implementation method of javaCode is simpler than xml, so if you need it, you can find the required information. The following are my four xml files, which represent the four animation types.

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 and transparent animation effect -->
<! -- FromAlpha the starting transparency of the animation is 1.0 completely opaque.
The toAlpha animation ends with the transparent 0.0 completely transparent
StartOffset set startup time
Duration Attribute animation duration
-->
<Alpha
Android: fromalphi = "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">
<! -- Animation effects of screen transfer and rotation -->
<! --
FromDegrees start angle
ToDegrees end angle
PivotX sets the X axis coordinates for rotation
-->
<Rotate
Android: fromDegrees = "0"
Android: toDegrees = "+ 360"
Android: Required Tx = "50%"
Android: Ty = "50%"
Android: duration= "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 scaling animation effect -->
<! --
FromXScale start X axis Coordinate
X axis coordinates at toXScale
FromYScale start y axis Coordinate
Coordinate of the Y axis at toYScale
PivotX sets the X axis coordinates for rotation
Ty sets the Y axis coordinates during rotation
Duration
-->

<Scale
Android: fromXScale = "1.0"
Android: toXScale = "0.0"
Android: fromYScale = "1.0"
Android: toYScale = "0.0"
Android: Required Tx = "50%"
Android: Ty = "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">
<! -- Animation effect of moving the image transfer position -->
<Translate
Android: fromxdel= "0%"
Android: toXDelta = "100%"
Android: fromYDelta = "0%"
Android: toYDelta = "0%"
Android: duration= "5000"
/>

</Set>

Below is the xml layout of the main interface

<? 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">

<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>

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 (savedInstanceState );
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 );
}
}

Now we have four types of animation effects. Another knowledge point is the speed issue in the animation. If you need it, go to Baidu to check it.

The implementation result is as follows:

 

 

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.