Android-animation animation effect implementation (XML form implementation)

Source: Internet
Author: User

1. Defining XML Animations

1) Define the XML file under the Anim folder

Explanation: The file under this folder will be the default animation file, if the file does not exist, you need to create

Display_result_anim.xml

<?XML version= "1.0" encoding= "Utf-8"?><Setxmlns:android= "Http://schemas.android.com/apk/res/android" >
<!--scale Animations--
< Scaleandroid:duration= "+"Android:fromxscale= "2.0"Android:fromyscale= "2.0"Android:interpolator= "@android: Anim/accelerate_decelerate_interpolator"Android:pivotx= "50%"Android:pivoty= "50%"Android:toxscale= "1.0"Android:toyscale= "1.0" />
< move animation!--position--
<Translateandroid:duration= "+"Android:fromydelta= "154.5%"Android:toydelta= "0"Android:fromxdelta= " -49.5%"Android:toxdelta= "0" > </Translate>
<!--transparency Animation--
<AlphaAndroid:fromalpha= "1"Android:toalpha= "0.5"android:duration= "+" /></Set>

Display_input_anim.xml

<?XML version= "1.0" encoding= "Utf-8"?><Setxmlns:android= "Http://schemas.android.com/apk/res/android" >    <Translateandroid:duration= "+"Android:fromxdelta= "0"Android:fromydelta= "44.1%"Android:toxdelta= "0"Android:toydelta= "0" />    <AlphaAndroid:fromalpha= "0"Android:toalpha= "1"android:duration= "+" /></Set>

2. References in code

Importandroid.view.animation.Animation;Importandroid.view.animation.AnimationUtils;Importandroid.view.animation.TranslateAnimation;PrivateAnimation myanimationinput;PrivateAnimation Myanimationresult; myanimationinput=animationutils.loadanimation (context, R.anim.display_input_anim); Myanimationresult=animationutils.loadanimation (Context,r.anim.display_result_anim); Myanimationinput.setfillafter (true); Myanimationresult.setfillafter (true); EditText Current=(EditText) Getcurrentview (); current.startanimation (myanimationinput); Next.startanimation (Myanimationresult) ;

Summary of Knowledge points:

1.Android:fromydelta= "44.1%" its attribute value has three forms

(1) If you write 33 directly, it means that the value of the animation owner (EditText) is 33px, according to +-the decision is on the owner or the next; if it is written in 33%, this is the representation, relative to the animation owner's own size of 33% distance, This size is the initial size of the animation owner, that is, the size of the time without animation, if written as 33%p, then the size of the parent container is relative to

(2) If it is forced to write 33DP, will be an error, stating that does not support such a way

(3) If it is a reference to @dimen, you will find that the result of the reference value is 0, that is, no animation effect, although it does not error

2. Effects of individual animations

Three kinds, the last one is

Rotate animation

< rotage      android:fromdegrees = "0"      android:todegrees= " -360"     android:pivotx= "50%"     Android :p ivoty= "50%"    android:duration="+"   />

property is the angle value, plus or minus indicates clockwise

Android-animation animation effect implementation (XML form implementation)

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.