First, familiarize yourself with the four types of animations
Anim/push_up_in.xml. Enter Animation
[Html]
<Set xmlns: android = "http://schemas.android.com/apk/res/android">
<Translate android: fromYDelta = "100% p" android: toYDelta = "0" android: duration = "300"/>
<Alpha android: fromAlpha = "0.0" android: toAlpha = "1.0" android: duration = "300"/>
</Set>
Android: fromYDelta = "100% p" android: toYDelta = "0" percentage of views reached
FromAlpha = "0.0" transparency is 0, 1 is not transparent
Anim/push_up_out.xml. Exit Animation
[Html]
<Set xmlns: android = "http://schemas.android.com/apk/res/android">
<Translate android: fromYDelta = "0" android: toYDelta = "-100% p" android: duration = "300"/>
<Alpha android: fromAlpha = "1.0" android: toAlpha = "0.0" android: duration = "300"/>
</Set>
Anim/push_left_in.xml. Enter from the right
[Html]
<Set xmlns: android = "http://schemas.android.com/apk/res/android">
<Translate android: fromXDelta = "100% p" android: toXDelta = "0" android: duration = "300"/>
<Alpha android: fromAlpha = "0.0" android: toAlpha = "1.0" android: duration = "300"/>
</Set>
Anim/push_left_out.xml. Exit from left
[Html]
<Set xmlns: android = "http://schemas.android.com/apk/res/android">
<Translate android: fromXDelta = "0" android: toXDelta = "-100% p" android: duration = "300"/>
<Alpha android: fromAlpha = "1.0" android: toAlpha = "0.0" android: duration = "300"/>
</Set>
Add ViewFlipper to the main. xml file
[Html]
<ViewFlipper
Android: id = "@ + id/flipper"
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"
Android: layout_marginBottom = "20dip"
Android: flipInterval = "2000">
<TextView
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"
Android: gravity = "center_horizontal"
Android: text = "@ string/animation_2_text_1"
Android: textSize = "26sp"/>
<TextView
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"
Android: gravity = "center_horizontal"
Android: text = "@ string/animation_2_text_2"
Android: textSize = "26sp"/>
<TextView
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"
Android: gravity = "center_horizontal"
Android: text = "@ string/animation_2_text_3"
Android: textSize = "26sp"/>
<TextView
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"
Android: gravity = "center_horizontal"
Android: text = "@ string/animation_2_text_4"
Android: textSize = "26sp"/>
</ViewFlipper>
// Set the animation www.2cto.com
MFlipper. setInAnimation (AnimationUtils. loadAnimation (this,
R. anim. push_up_in ));
// Set the exit Animation
MFlipper. setOutAnimation (AnimationUtils. loadAnimation (this,
R. anim. push_up_out ));
// Start the animation
MFlipper. startFlipping ();
At the same time, several animations slide_in_left.xml are also available in android. R. anim from the left. slide_out_right.xml
Author: Android_Xiaoqi