stick one View To another View - Android User Interface

Android examples for User Interface:View

Description

stick one View To another View

Demo Code


//package com.java2s;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.graphics.Rect;

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 stickTo(final View v, View viewToStickTo,
            ViewGroup main) {/*  www .j  a  v a 2s .co m*/
        v.setLayerType(View.LAYER_TYPE_HARDWARE, null);

        v.getDrawingRect(mTmpRect);
        main.offsetDescendantRectToMyCoords(v, mTmpRect);

        v.animate().translationY(viewToStickTo.getHeight() - mTmpRect.top)
                .alpha(1).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