Created
November 12, 2014 16:41
-
-
Save rogerpujol/3007c0262002764024b3 to your computer and use it in GitHub Desktop.
Example that shows how to implement an Object Animator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Object Animator Example | |
* Check for more info: http://developer.android.com/guide/topics/graphics/prop-animation.html | |
*/ | |
private Animator mMyAnimator; | |
private int mDuration = 3000; //Duration in millis | |
private MyObject object; | |
private float mInitialVal = 0.0f; | |
private float mInitialVal = 0.0f; | |
/** | |
* ObjectAnimator, can be type ofFloat, ofInt, ofObject...etc | |
* this -> refers to the class itself, so "phase" will refer to | |
* "someProperty" -> refers to mSomeProperty of the object ( object.mSomeProperty) | |
*/ | |
mMyAnimator = ObjectAnimator.ofFloat(object, "someProperty", mInitivalVal, mFinalVal).setDuration(mDuration); | |
mMyAnimator.start(); | |
/** | |
* setInterpolator received an interpolator. | |
* Interpolators can be type: http://developer.android.com/reference/android/view/animation/Interpolator.html | |
*/ | |
mMyAnimator.setInterpolator(new AccelerateDecelerateInterpolator();); | |
mMyAnimator.addListener(new AnimatorListenerAdapter() { | |
@Override | |
public void onAnimationStart(Animator animation) { | |
super.onAnimationStart(animation); | |
//Called when the animation starts | |
} | |
@Override | |
public void onAnimationEnd(Animator animation) { | |
super.onAnimationEnd(animation); | |
//Called when the animation ends | |
} | |
@Override | |
public void onAnimationRepeat(Animator animation){ | |
super.onAnimationRepeat(animation); | |
//Called when the animation repeats | |
} | |
@Override | |
public void onAnimationCancel(Animator animation){ | |
super.onAnimationCancel(animation); | |
//Called when the animation is cancelled | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment