Simple animation of the [Android] interface switch

Source: Internet
Author: User

1. Create a new displacement animation xml file

activate animation in Activity

To load an animation resource file using the Animationutils class

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     = "" >  </ translate  >  
View child=New Indexview (this). Getmemberview (); Child.startanimation ( Animationutils.loadanimation (This, r.anim.left_to_right));

2. Fade animation

Current fade-out interface and execution time

Fade out process, fading screen is in wait state

The second interface fades in and his execution time

After the first interface finishes executing, delete the

 Packagecom.tsh.lottery.utils;ImportAndroid.support.v4.view.ViewPager;ImportAndroid.view.View;ImportAndroid.view.ViewGroup;Importandroid.view.ViewParent;Importandroid.view.animation.AlphaAnimation;Importandroid.view.animation.Animation;ImportAndroid.view.animation.Animation.AnimationListener; Public classFadeutil {/*** Fade Out interface *@paramView interface *@paramDuration Execution Time*/     Public Static voidFadeOut (FinalView View,Longduration) {alphaanimation alphaanimation=NewAlphaanimation (1, 0);        Alphaanimation.setduration (duration);        View.startanimation (alphaanimation); //Listen for animation end, delete view elementAlphaanimation.setanimationlistener (NewAnimationlistener () {@Override Public voidOnanimationstart (Animation Animation) {} @Override Public voidonanimationrepeat (Animation Animation) {} @Override Public voidonanimationend (Animation Animation) {viewgroup VG=(ViewGroup) view.getparent ();            Vg.removeview (view);    }        }); }    /*** fade-in interface *@paramView interface *@paramDelay Time *@paramDuration Execution Time*/     Public Static voidFadeIn (View view,LongDelayLongduration) {alphaanimation alphaanimation=NewAlphaanimation (0, 1); //set start time delayAlphaanimation.setstartoffset (delay);        Alphaanimation.setduration (duration);    View.startanimation (alphaanimation); }}
Fadeutil.fadeout (Child, 2000);
Fadeutil.fadein (Child, 2000,2000);

Simple animation of the [Android] interface switch

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.