[Android] simple animation for UI switching, android Switching
1. Create an xml file for the displacement Animation
Enable animation in Activity
Use the AnimationUtils class to load animation resource files
Left_to_right.xml
<?xml version="1.0" encoding="utf-8"?><translate xmlns:android="http://schemas.android.com/apk/res/android" android:fromXDelta="100%" android:toXDelta="0" android:duration="3000" ></translate>
View child=new IndexView(this).getMemberView();child.startAnimation(AnimationUtils.loadAnimation(this, R.anim.left_to_right));
2. Fade-in and fade-out animation
Current fade-out interface and execution time
The Fade-In interface is in the waiting status during the fade-out process.
The second interface fades in and executes the time
After the first interface is executed, delete it.
Package com. tsh. lottery. utils; import android. support. v4.view. viewPager; import android. view. view; import android. view. viewGroup; import android. view. viewParent; import android. view. animation. alphaAnimation; import android. view. animation. animation; import android. view. animation. animation. animationListener; public class FadeUtil {/*** fade-out interface * @ param view Interface * @ param duration execution time */public static void fadeOut (final View view, long duration) {AlphaAnimation alphaAnimation = new AlphaAnimation (1, 0); alphaAnimation. setDuration (duration); view. startAnimation (alphaAnimation); // listens to the animation end and deletes the View element alphaAnimation. configure (new AnimationListener () {@ Override public void onAnimationStart (Animation animation) {}@ Override public void Merge (Animation animation) {ViewGroup vg = (ViewGroup) view. getParent (); vg. removeView (view );}});} /*** quiet interface ** @ param view Interface * @ param delay time * @ param duration execution time */public static void fadeIn (View view, long delay, long duration) {AlphaAnimation alphaAnimation = new AlphaAnimation (0, 1); // set the start time delay alphaAnimation. setStartOffset (delay); alphaAnimation. setDuration (duration); view. startAnimation (alphaAnimation );}}
FadeUtil.fadeOut(child, 2000);
FadeUtil.fadeIn(child, 2000,2000);