Android animation XML (2)

Source: Internet
Author: User

Animation can also be stored in an XML file, which improves the maintainability of the program. To write an animation in XML, follow these steps:

1. Create a folder named anim under the res folder

2. Create an xml file and add the set tag first. Modify the tag as follows:

<Set xmlns: android = "http://schemas.android.com/apk/res/android"
Android: interpolator = "@ android: anim/accelerate_interpolator">
 
</Set>


3. Add the rotate, alpha, scale, or translate tag to the tag.

4. Use AnimationUtils in the code to load the xml file and generate the Animation object.

Alpha Animation


[Java]
<SPAN style = "FONT-SIZE: 18px"> <? Xml version = "1.0" encoding = "UTF-8"?>
<Set xmlns: android = "http://schemas.android.com/apk/res/android"
Android: interpolator = "@ android: anim/accelerate_interpolator">
<Alpha
Android: fromalphi = "1.0"
Android: toAlpha = "0.0"
Android: startOffset = "500"
Android: duration= "2000"
/>
 
</Set> </SPAN>

<? Xml version = "1.0" encoding = "UTF-8"?>
<Set xmlns: android = "http://schemas.android.com/apk/res/android"
Android: interpolator = "@ android: anim/accelerate_interpolator">
<Alpha
Android: fromalphi = "1.0"
Android: toAlpha = "0.0"
Android: startOffset = "500"
Android: duration= "2000"
/>

</Set> Animation a = AnimationUtils. loadAnimation (this, R. anim. alpha );
Iv. startAnimation ();

Scale Animation


[Html]
<SPAN style = "FONT-SIZE: 18px"> <? Xml version = "1.0" encoding = "UTF-8"?>
<Set xmlns: android = "http://schemas.android.com/apk/res/android"
Android: interpolator = "@ android: anim/accelerate_interpolator">
<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= "2000"
/>
 
</Set> </SPAN>

<? Xml version = "1.0" encoding = "UTF-8"?>
<Set xmlns: android = "http://schemas.android.com/apk/res/android"
Android: interpolator = "@ android: anim/accelerate_interpolator">
<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= "2000"
/>

</Set>
Rotate Animation


[Html]
<SPAN style = "FONT-SIZE: 18px"> <? Xml version = "1.0" encoding = "UTF-8"?>
<Set xmlns: android = "http://schemas.android.com/apk/res/android"
Android: interpolator = "@ android: anim/accelerate_interpolator">
<Rotate
Android: fromDegrees = "0"
Android: toDegrees = "400"
Android: Required Tx = "50%"
Android: Ty = "50%"
Android: duration= "3000"
/>
 
</Set> </SPAN>

<? Xml version = "1.0" encoding = "UTF-8"?>
<Set xmlns: android = "http://schemas.android.com/apk/res/android"
Android: interpolator = "@ android: anim/accelerate_interpolator">
<Rotate
Android: fromDegrees = "0"
Android: toDegrees = "400"
Android: Required Tx = "50%"
Android: Ty = "50%"
Android: duration= "3000"
/>

</Set>
Translate Animation


[Html]
<SPAN style = "FONT-SIZE: 18px"> <? Xml version = "1.0" encoding = "UTF-8"?>
<Set xmlns: android = "http://schemas.android.com/apk/res/android"
Android: interpolator = "@ android: anim/accelerate_interpolator">
<Translate
Android: fromxdel= "50%"
Android: toXDelta = "100%"
Android: fromYDelta = "50%"
Android: toYDelta = "100%"
Android: duration= "3000"
/>
 
</Set> </SPAN>

<? Xml version = "1.0" encoding = "UTF-8"?>
<Set xmlns: android = "http://schemas.android.com/apk/res/android"
Android: interpolator = "@ android: anim/accelerate_interpolator">
<Translate
Android: fromxdel= "50%"
Android: toXDelta = "100%"
Android: fromYDelta = "50%"
Android: toYDelta = "100%"
Android: duration= "3000"
/>

</Set>
Here we will focus on android: javastx and android: policty and android: fromXDelta, android: toXDelta

Android: Required Tx = "50" use absolute coordinates

Android: relative Tx = "50%" relative to yourself

Android: relative Tx = "50% p" relative to parent Control

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.