Advertisement
Guest User

SlideFromRightAnimation.java

a guest
Nov 19th, 2014
721
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. //=====================================================
  2. public class SlideFromRightAnimation {
  3.  
  4.     private float end = 0, start=0;
  5.     private int duration = 3300;
  6.     private TimeInterpolator interpolator = new AccelerateInterpolator();
  7.    
  8.     //===================================
  9.     public SlideFromRightAnimation(Activity act, int duration){
  10.         if(android.os.Build.VERSION.SDK_INT>=13){
  11.             Point p = new Point();
  12.             act.getWindowManager().getDefaultDisplay().getSize(p);
  13.             start = p.x;
  14.         }else{
  15.             DisplayMetrics d = new DisplayMetrics();
  16.             act.getWindowManager().getDefaultDisplay().getMetrics(d);
  17.             start = d.widthPixels;
  18.         }
  19.         this.duration = duration;
  20.     }
  21.  
  22.     //===================================
  23.     public void setInterpolator(TimeInterpolator ip){interpolator=ip;}
  24.  
  25.     //===================================
  26.     public ValueAnimator getAnimator(View v){
  27.         ValueAnimator anim = ObjectAnimator.ofFloat(v, "translationX", start,end);
  28.         anim.setInterpolator(interpolator);
  29.         anim.setDuration(duration);
  30.         return anim;
  31.     }
  32.    
  33.     //===================================
  34.     public void start(View v){
  35.         ValueAnimator anim = getAnimator(v);
  36.         anim.start();
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement