Android Animation knowledge summary Animation AnimationSet LayoutAnimation

Source: Internet
Author: User

Android Animation knowledge summary Animation AnimationSet LayoutAnimation
This article by PurpleSword (jzj1993) original, reproduced please indicate the original web site http://blog.csdn.net/jzj1993
There are several common animations

Control View animation (such as the Circular progress bar in the Dialog Window) LayoutAnimation animation of the ViewGroup, each sub-control follows the set sequence and delays playing the animation.
Commonly used anim/*. xml definition for animation

Allows you to define animations in xml. Tags can be directly defined or placed in In the tag, the animation defined in it starts playing at the same time. Both can use AnimationUtils. LoadAnimationMethod load. If the set tag is defined, the returned value is the AnimationSet instance (which is inherited from Animation ). Some attributes set in the set tag directly overwrite the corresponding attributes of the Animation defined in it, while other attributes of the AnimationSet inherited from the Animation are invalid, the following is an official description of the AnimationSet class.
Represents a group of Animations that shoshould be played together. the transformation of each individual animation are composed together into a single transform. if AnimationSet sets any properties that its children also set (for example, duration or fillBefore), the values of AnimationSet override the child values.

The way that AnimationSet inherits behavior from Animation is important to understand. some of the Animation attributes applied to AnimationSet affect the AnimationSet itself, some are pushed down to the children, and some are ignored, as follows:

    Duration, repeatMode, fillBefore, fillAfter: These properties, when set on an AnimationSet object, will be pushed down to all child animations. repeatCount, fillEnabled: These properties are ignored for AnimationSet. startOffset, parameter interpolator: These properties apply to the AnimationSet itself.
    Starting android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH, The behavior of these properties is the same in XML resources and at runtime (prior to that release, the values set in XML were ignored for AnimationSet). That is, calling setDuration(500)On an AnimationSet has the same effect as declaring android:duration="500"In an XML resource for an AnimationSet object.


    Regular tween animation:Bounce (mobile)
    Layout/activity_welcome_anim.xml
    (0% p indicates the percentage of the size of the parent component)

    "1.0"Encoding = "UTF-8"?> Http://schemas.android.com/apk/res/android"> "500"Android: fromXDelta = "0"Android: fromYDelta = "0% p"Android: interpolator = "@ Android: anim/accelerate_interpolator"Android: toXDelta = "0"Android: toYDelta = "42% p"/> "350"Android: fromXDelta = "0"Android: fromYDelta = "0"Android: interpolator = "@ Android: anim/decelerate_interpolator"Android: startOffset = "500"Android: toXDelta = "0"Android: toYDelta = "-21% p"/> "350"Android: fromXDelta = "0"Android: fromYDelta = "0"Android: interpolator = "@ Android: anim/accelerate_interpolator"Android: startOffset = "850"Android: toXDelta = "0"Android: toYDelta = "21% p"/> "250"Android: fromXDelta = "0"Android: fromYDelta = "0"Android: interpolator = "@ Android: anim/decelerate_interpolator"Android: startOffset = "1200"Android: toXDelta = "0"Android: toYDelta = "-10% p"/> "250"Android: fromXDelta = "0"Android: fromYDelta = "0"Android: interpolator = "@ Android: anim/accelerate_interpolator"Android: startOffset = "1450"Android: toXDelta = "0"Android: toYDelta = "10% p"/> "150"Android: fromXDelta = "0"Android: fromYDelta = "0"Android: interpolator = "@ Android: anim/decelerate_interpolator"Android: startOffset = "1700"Android: toXDelta = "0"Android: toYDelta = "-5% p"/> "150"Android: fromXDelta = "0"Android: fromYDelta = "0"Android: interpolator = "@ Android: anim/accelerate_interpolator"Android: startOffset = "1850"Android: toXDelta = "0"Android: toYDelta = "5% p"/>

    Another example is the regular Animation: Scaling and transparency.
    "1.0"Encoding = "UTF-8"?> Http://schemas.android.com/apk/res/android"> "800"Android: fromXScale = "0.0"Android: fromYScale = "0.0"Android: Required Tx = "50%"Android: Required ty = "50%"Android: toXScale = "1.0"Android: toYScale = "1.0"/> 800"Android: fromAlpha = "0.0"Android: toAlpha = "1.0"/>
    Another example is the floating effect (movement and transparency)
    "1.0"Encoding = "UTF-8"?> Http://schemas.android.com/apk/res/android"Android: interpolator = "@ Android: anim/linear_interpolator"> "500"Android: fromXDelta = "0"Android: fromYDelta = "5%"Android: toXDelta = "0"Android: toYDelta = "0%"/> 500"Android: fromAlpha = "0.0"Android: toAlpha = "1.0"/> 100"Android: fromAlpha = "1.0"Android: startOffset = "1400"Android: toAlpha = "1.0"/>
    You can use a Java program to load

    This. SetContentView (R. layout. Activity_welcome);
    Anim = AnimationUtils. loadAnimation ( This, R. anim. Welcome_anim); // After the animation effect is executed, the View object is retained at the ending position.
    Anim. setFillEnabled ( True); Anim. setFillAfter ( True);

    This. FindViewById (R. id. Point). SetAnimation (anim );


    You can also set an animation listener.
    Anim. setAnimationListener (listener );
    /**
    * Animation listener
    */
    PrivateAnimationListener listener = NewAnimationListener (){
    @ Override
    Public VoidOnAnimationEnd (Animation animation ){
    // StartMain ();
    }
    @ Override
    Public VoidOnAnimationStart (Animation animation ){
    }
    @ Override
    Public VoidOnAnimationRepeat (Animation animation ){
    }
    };
    Animation loading in Dialog
    LayoutInflater inflater = LayoutInflater. from (context); View v = inflater. inflate (R. layout. Dialog_voice, Null); ImageView img = (ImageView) v. findViewById (R. id. Dialog_img); Animation anim = AnimationUtils. loadAnimation (context, R. anim. Center_rotate_repeat); Img. startAnimation (anim ); NewAlertDialog. Builder (context). setView (v );
    Set an animation for the entire DialogDialog. getWindow (). setWindowAnimations (R. style. Quick_scale_anim);
    Set an animation for PopupWindowPop. setAnimationStyle (R. style. Quick_scale_anim);


    Activity switching Animation
    Code to implement Activity switching Animation
    StartActivity ( NewIntent ( This, ListAlarm. Class); OverridePendingTransition (R. anim. Anim_activity_in, R. anim. Anim_activity_unchange);

    Or
    ActivityGuide. This. Finish (); overridePendingTransition (R. anim. Alpha_stay, R. anim. Alpha_exit);

    Define Activity switching animation in XML
    Activity switching Animation: The SingleInstance attribute cannot be set, causing animation failure.


    Manifest. xml"@ Style/app_theme"> ". Ui. ActivityWelcome"Android: theme = "@ Style/app_theme_fullscreen">
    Style. xml

    Anim/quick_alpha_enter.xml
    Anim/quick_alpha_stay.xml


    LayoutAnimation
    1. define a child View animation in layout_anim_item.xml.

    2. In layout_anim.xmlDefine Layout animation and reference the child View animation
    Http://schemas.android.com/apk/res/android"Android: animation = "@ Anim/layout_anim_item"Android: animationOrder = "Normal"Android: delay = "0.25"/>

    3. Reference custom Layout animation in ViewGroup "@ Anim/layout_anim">



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.