Java tutorial
//package com.java2s; /* * Copyright (C) 2014 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License */ import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.view.View; import android.view.ViewPropertyAnimator; import android.view.animation.Interpolator; import android.view.animation.PathInterpolator; public class Main { public static final int DEFAULT_DURATION = -1; public static final int NO_DELAY = 0; public static final Interpolator EASE_OUT = new PathInterpolator(0.4f, 0.0f, 1.0f, 1.0f); /** * Scales out the view from actual dimensions to 0. * @param view The view to scale. * @param durationMs The duration of the scaling in milliseconds. */ public static void scaleOut(final View view, int durationMs) { AnimatorListenerAdapter listener = new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { view.setVisibility(View.GONE); } @Override public void onAnimationCancel(Animator animation) { view.setVisibility(View.GONE); view.setScaleX(0); view.setScaleY(0); } }; scaleInternal(view, 1 /* startScaleValue */, 0 /* endScaleValue */, durationMs, NO_DELAY, listener, EASE_OUT); } private static void scaleInternal(final View view, int startScaleValue, int endScaleValue, int durationMs, int startDelay, AnimatorListenerAdapter listener, Interpolator interpolator) { view.setScaleX(startScaleValue); view.setScaleY(startScaleValue); final ViewPropertyAnimator animator = view.animate(); animator.cancel(); animator.setInterpolator(interpolator).scaleX(endScaleValue).scaleY(endScaleValue).setListener(listener) .withLayer(); if (durationMs != DEFAULT_DURATION) { animator.setDuration(durationMs); } animator.setStartDelay(startDelay); animator.start(); } }