[Android] simple animation for UI switching, android Switching

Source: Internet
Author: User

[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);

 

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.