Android Animator Animation Animation effect detailed

Source: Internet
Author: User
Tags xml file example

Android's animation consists of four types of XML in the Alpha gradient transparency animation effect scale gradient dimension scaling animation effect translate picture conversion position move animation effect rotate Picture transfer rotation animation effect Javacode Alphaanimation Gradient Transparency Animation effect scaleanimation gradient dimension stretch animation effect translateanimation picture transition position Move animation effect rotateanimation Picture Transfer rotate animation effect Android Animation mode Animatio N There are two main modes of animation: one is tweened animation (gradient animation) XML Javacodealphaalphaanimationscalescaleanimation one is frame by frame (Picture conversion animation) XML Javacodetranslatetranslateanimationrotaterotateanimation How to define animations in an XML file ① open Eclipse, create a new Android project ② Create a new Anim folder in the Res directory ③ create a new myanim.xml in the Anim directory (note file name lowercase) ④ Add animation code to XML Android Animation parsing--xml How to use the animation effect in XML public static Animation Loadanimation (context context, int id)///First parameter context for program contexts//second parameter ID for a reference to an animated XML file Example: myanimation= animationutils.loadanimation (this,r.anim.my_action); Use the static method of the Animationutils class Loadanimation () to load an animated XML file in XML How to define animation in Java code private Animation Myanimation_alpha; Private Animation Myanimation_scale; Private Animation myanimation_translate; Private Animation myanimation_rotate; Initializes an instance object Myanimation_alpha=new alphaanimation (0.1f, 1.0f) according to the respective construction method; Myanimation_scale =new scaleanimation (0.0f, 1.4f, 0.0f, 1.4f, Animation.relative_to_self, 0.5f, animation.relative_to_ Self, 0.5f); Myanimation_translate=new translateanimation (30.0f, -80.0f, 30.0f, 300.0f); Myanimation_rotate=new rotateanimation (0.0f, +350.0f, Animation.relative_to_self,0.5f,animation.relative_to_self, 0.5f); Android Animation parsing--javacodealphaanimation①alphaanimation class object definition private Alphaanimation myanimation_alpha; Alphaanimation (float fromalpha, float toalpha)//first parameter Fromalpha for animation start time transparency//second parameter ToalpHa for animation end time Transparency myanimation_alpha=new alphaanimation (0.1f, 1.0f); Description://0.0 indicates full transparency//1.0 indicates full opacity//Set animation duration myanimation_alpha.setduration (5000); Scaleanimation private alphaanimation Myanimation_alpha; Scaleanimation (float FromX, float toX, float fromY, float toY, int pivotxtype, float pivotxvalue, int pivotytype, float pi Votyvalue)///////The first parameter fromx the scaling dimension on the x-coordinate at the start of the animation//The second parameter tox the scaling dimension on the x-coordinate at the end of the animation//The third parameter fromy the scaling dimension on the y-coordinate at the start of the animation// The fourth parameter, toy, is the scaling dimension on the y-coordinate at the end of the animation/* Description: The above four attribute values 0.0 means that shrinking to no 1.0 means that a normal non-scaling value of less than 1.0 means that the shrink value is greater than 1.0 to enlarge *///fifth parameter Pivotxtype to animate on x-axis relative to object position type/ /Sixth parameter pivotxvalue is the start position of the animation relative to the object's X coordinate//seventh parameter Pivotxtype for the animation on the y-axis relative to the object position type//eighth parameter pivotyvalue the start position of the animation relative to the object's y-coordinate Myanimation_scale =new scaleanimation (0.0f, 1.4f, 0.0f, 1.4f, Animation.relative_to_self, 0.5f, animation.relative_to_ Self, 0.5f); Set animation duration myanimation_scale.setduration (700); Translateanimation private alphaanimation Myanimation_alpha; Translateanimation (float Fromxdelta, float toxdelta, float fromydelta, float toydelta)//First parameter Fromxdelta move at the x-coordinate of the start of the animationPosition//The second parameter Toxdelta is the moving position at the end of the animation at the x-coordinate//The third parameter fromydelta the move position on the y-coordinate at the start of the animation//fourth parameter toydelta the position of the motion at the end of the animation//Set the duration of the animation Myanimation_translate.setduration (2000); Rotateanimation private alphaanimation Myanimation_alpha; Rotateanimation (float fromdegrees, float todegrees, int pivotxtype, float pivotxvalue, int pivotytype, float pivotyvalue) The first parameter fromdegrees the rotation angle at the start of the animation//The second parameter todegrees the angle to which the animation is rotated///The third parameter Pivotxtype for the animation on the x-axis relative to the object position type// The fourth parameter pivotxvalue the start position of the animation relative to the object's x-coordinate,//the fifth parameter Pivotxtype for the animation on the y-axis relative to the object position type//sixth parameter pivotyvalue the start position of the animation relative to the object's y-coordinate Myanimation_rotate=new rotateanimation (0.0f, +350.0f, Animation.relative_to_self,0.5f,animation.relative_to_self, 0.5f); Myanimation_rotate.setduration (3000); How to use the animation effect in Java code using the method inherited from the View parent class Startanimation () To add an animated effect to view or subclass view and so on public void startanimation (Animation Animation)

Android Animator Animation animation effect

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.