Home » Android » Android animation usage

Android animation usage

below is a record of what I see in just for future use, refer to


layouyAnimation ViewGroup is used to specify an animation for ViewGroup, so when the appearance of the

will have the elements of animation

the following code is an example of layouyAnimation for ListView, with the effect that every Item is

flying from the right

1. now defines the animation effects of item

<, XML, version=, 1, encoding=, UTF-8, >
Android:duration= "300""
Android:interpolator= "@android:anim/accelerate_interpolator""
Android:shareInterpolator= "true" >
Android:fromAlpha= "0""
Android:toAlpha= "1" / >
Android:fromXDelta= "500""
Android:toXDelta= "0" / >

Android:interpolator is the interpolator . The speed of the insertion period null animation. If not specified, the default interpolator
will be used

android:shareInterpolator= "true" in the collection and the animation is set to share the same interpolator, if the collection does not specify interpolation, then the sub animation requires a separate interpolator for or use the default @android:anim/accelerate_interpolator
Acceleration and deceleration interpolator

2. defines LayoutAnimation

anim/anim_layout, "

Xmlns:android= "http://schemas.android.com/apk/res/android""
Android:delay= "0.5""
Android:animationOrder= "reverse""
Android:animation= "@anim/anim_item" />
android:delay said the element start animation time delay, if the child admission animation time period is 300ms, so that each sub 0.5 elements will delay 150ms admission will play animation, generally speaking, the first child element of the 150ms began to play the admission delay animation, second sub elements play admission delay 300ms animation, and so analogy

android:animationOrder represents the order in which child elements are animated. There are three options: normal, reverse, and random

normal:, play the admission animation


reverse:, reverse play, admission animation,

random: random access animation

3. specifies the android:layoutAnimation= "@anim/anim_layout" for ViewGroup so that each Item will have an animated

 Android:id= "@+id/list""
Android:layout_width= "match_parent""
Android:layout_height= "match_parent""
Android:layoutAnimation= "@anim/anim_layout""
Android:background= "#fff4f7f9""
Android:cacheColorHint= "#00000000""
Android:divider= "#dddbdb""
Android:dividerHeight= "1.0px""
Android:listSelector= "@android:color/transparent" />

The code above is the basic step in setting up layoutAnimation in XML. Here is a implementation in Java code

, Animation, animation = AnimationUtils.loadAnimation (DemoActivity_2.this, R.anim.anim_item);
LayoutAnimationController controller = new LayoutAnimationController (animation);
Controller.setDelay (0.5f);
Controller.setOrder (LayoutAnimationController.ORDER_NORMAL);
ListView.setLayoutAnimation (controller);

Activity toggle effect

in startActivity (Intent) and finish () call overridePendingTransition (R.anim.enter_anim, R.anim.exit_anim), you can achieve the switching effect of Activity