switch Showed View from one View to another - Android User Interface

Android examples for User Interface:View Hide Show

Description

switch Showed View from one View to another

Demo Code


//package com.java2s;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.view.View;

public class Main {
    @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
    public static void switchShowedView(Context context,
            final View fromView, final View toView) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {

            int shortAnimTime = context.getResources().getInteger(
                    android.R.integer.config_shortAnimTime);

            fromView.setVisibility(View.GONE);
            fromView.animate().setDuration(shortAnimTime).alpha(0)
                    .setListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(Animator animation) {
                            fromView.setVisibility(View.GONE);
                        }/*  w  w w .java2s  .c o  m*/
                    });

            toView.setVisibility(View.VISIBLE);
            toView.animate().setDuration(shortAnimTime).alpha(1)
                    .setListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(Animator animation) {
                            toView.setVisibility(View.VISIBLE);
                        }
                    });
        } else {
            // The ViewPropertyAnimator APIs are not available, so simply show
            // and hide the relevant UI components.
            fromView.setVisibility(View.GONE);
            toView.setVisibility(View.VISIBLE);
        }
    }
}

Related Tutorials