start Bounce With Thumb - Android Animation

Android examples for Animation:Translate Animation

Description

start Bounce With Thumb

Demo Code


//package com.java2s;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;

import android.view.View;

public class Main {
    private final static int DEFAULT_TRANSLATION_POSITION = 0;
    private final static int DEFAULT_TRANSLATION_DELTA = 30;

    public static AnimatorSet startBounceWithThumb(View thumbView) {
        return startBounceWithThumb(thumbView,
                DEFAULT_TRANSLATION_POSITION, DEFAULT_TRANSLATION_DELTA,
                null);/*  w  w  w. jav a2s . c o m*/
    }

    public static AnimatorSet startBounceWithThumb(View thumbView,
            float endPositionX, float deltaX) {
        return startBounceWithThumb(thumbView, endPositionX, deltaX, null);
    }

    public static AnimatorSet startBounceWithThumb(View thumbView,
            float endPositionX, float deltaX, Integer duration) {
        AnimatorSet as = new AnimatorSet();
        as.playSequentially(ObjectAnimator.ofFloat(thumbView,
                "translationX", endPositionX - deltaX / 4), ObjectAnimator
                .ofFloat(thumbView, "translationX", endPositionX + deltaX
                        / 8), ObjectAnimator.ofFloat(thumbView,
                "translationX", endPositionX));
        if (duration == null)
            duration = thumbView.getResources().getInteger(
                    android.R.integer.config_shortAnimTime) / 2;
        as.setDuration(duration);
        as.start();
        return as;
    }
}

Related Tutorials