Create Animation with ObjectAnimator and Keyframe - Android Animation

Android examples for Animation:Animation Creation

Description

Create Animation with ObjectAnimator and Keyframe

Demo Code


//package com.java2s;
import android.animation.Keyframe;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.view.View;

public class Main {
    public static ObjectAnimator doAnimation(View view) {
        int delta = 300;

        PropertyValuesHolder pvhTranslateX = PropertyValuesHolder
                .ofKeyframe("translationX", Keyframe.ofFloat(0f, 0),
                        Keyframe.ofFloat(.10f, -delta),
                        Keyframe.ofFloat(.26f, delta),
                        Keyframe.ofFloat(.42f, -delta),
                        Keyframe.ofFloat(.58f, delta),
                        Keyframe.ofFloat(.74f, -delta),
                        Keyframe.ofFloat(.90f, delta),
                        Keyframe.ofFloat(1f, 0f));

        return ObjectAnimator.ofPropertyValuesHolder(view, pvhTranslateX)
                .setDuration(1000);//from  www.  ja  va 2 s. com
    }
}

Related Tutorials