Skip to content

Instantly share code, notes, and snippets.

@lalitsharma1607
Last active April 9, 2018 12:24
Show Gist options
  • Save lalitsharma1607/a85c71369e301e12aa65f1352a07e20e to your computer and use it in GitHub Desktop.
Save lalitsharma1607/a85c71369e301e12aa65f1352a07e20e to your computer and use it in GitHub Desktop.
private void scaleAndAnimateToTop() {
ScaleAnimation animation = new ScaleAnimation(5.0f, 1.0f, 5.0f, 1.0f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
animation.setDuration(1000);
mView.startAnimation(animation);
}
private void animateInArc() {
Path path = new Path();
path.arcTo(0f, 0f, 500f, 500f, 90f, 270f, true);
ObjectAnimator animator = ObjectAnimator.ofFloat(findViewById(R.id.imgView), View.X, View.Y, path);
animator.setDuration(1000);
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
Path path = new Path();
path.arcTo(0f, 0f, 500f, 500f, -270f, 270f, true);
ObjectAnimator animator = ObjectAnimator.ofFloat(findViewById(R.id.imgView), View.X, View.Y, path);
animator.setDuration(1000);
animator.start();
}
});
animator.start();
}
private void translateFromCenter() {
TranslateAnimation animation = new TranslateAnimation(0.0f, 0.0f,
300.0f/*adjust the height as per your need*/, 0.0f);
animation.setDuration(700);
mView.startAnimation(animation);
}
private void startMultipleAnimations() {
final AnimationSet set = new AnimationSet(true);
final ScaleAnimation scaleAnimation = new ScaleAnimation(5.0f, 1.0f, 5.0f, 1.0f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
TranslateAnimation animation = new TranslateAnimation(0.0f, 0.0f,
300.0f, 0.0f);
AlphaAnimation alphaAnimation = new AlphaAnimation(0.0f, 1.0f);
set.setDuration(1000);
set.addAnimation(scaleAnimation);
set.addAnimation(animation);
set.addAnimation(alphaAnimation);
set.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
mView.startAnimation(set);
}
private void startShakeAnimation(){
RotateAnimation rotateAnimation =new RotateAnimation(0.0f,5f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation.setRepeatMode(Animation.REVERSE);
//create cycleInterpolator
CycleInterpolator cycleInterpolator = new CycleInterpolator(5);
//setting interpolator to the animation
rotateAnimation.setInterpolator(cycleInterpolator);
rotateAnimation.setDuration(500);
mView.startAnimation(rotateAnimation);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment