focus On Animation - Android Animation

Android examples for Animation:Animation Creation

Description

focus On Animation

Demo Code


//package com.java2s;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.graphics.Rect;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.Interpolator;

public class Main {
    private static final int ANIMATE_DURATION = 700;
    private static final Interpolator ANIMATE_INTERPOLATOR = new AccelerateDecelerateInterpolator();
    private final static Rect mTmpRect = new Rect();

    public static void focusOn(final View v, View focusView, ViewGroup main) {

        v.setOnTouchListener(new View.OnTouchListener() {
            @Override/*  w  w  w. j  a va2s. c om*/
            public boolean onTouch(View view, MotionEvent motionEvent) {
                return true;
            }
        });

        v.setLayerType(View.LAYER_TYPE_HARDWARE, null);

        focusView.getDrawingRect(mTmpRect);

        main.offsetDescendantRectToMyCoords(focusView, mTmpRect);

        v.animate().translationY(-mTmpRect.top)
                .setDuration(ANIMATE_DURATION)
                .setInterpolator(ANIMATE_INTERPOLATOR)
                .setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        v.setLayerType(View.LAYER_TYPE_NONE, null);
                        super.onAnimationEnd(animation);
                    }
                }).start();
    }
}

Related Tutorials