Advertisement
kang-emus

Animasi button

Apr 7th, 2020
1,315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.85 KB | None | 0 0
  1. ///Klik
  2. _view.setOnTouchListener(new OnTouchListener() {
  3.                 @Override public boolean onTouch(View v, MotionEvent event) {
  4.                         switch(event.getAction()) {
  5.                                 case
  6.                                 MotionEvent.ACTION_DOWN:
  7.                                 {
  8.                         _Anim(_view, "elevation", 5, 70);
  9.                         _Anim(_view, "scaleX", 0.9d, 70);
  10.                         _Anim(_view, "scaleY", 0.9d, 70);
  11.                         t = new TimerTask() {
  12.                             @Override
  13.                             public void run() {
  14.                                 runOnUiThread(new Runnable() {
  15.                                     @Override
  16.                                     public void run() {
  17.                                         _Anim(_view, "elevation", 1, 100);
  18.                                         _Anim(_view, "scaleX", 0.88d, 100);
  19.                                         _Anim(_view, "scaleY", 0.88d, 100);
  20.                                     }
  21.                                 });
  22.                             }
  23.                         };
  24.                         _timer.schedule(t, (int)(70));
  25.                         break; }
  26.                     case
  27.                     MotionEvent.ACTION_UP:
  28.                                 {
  29.                         t.cancel();
  30.                         _Anim(_view, "elevation", 40, 100);
  31.                         _Anim(_view, "scaleX", 1.1d, 100);
  32.                         _Anim(_view, "scaleY", 1.1d, 100);
  33.                         t = new TimerTask() {
  34.                             @Override
  35.                             public void run() {
  36.                                 runOnUiThread(new Runnable() {
  37.                                     @Override
  38.                                     public void run() {
  39.                                         _Anim(_view, "elevation", 25, 100);
  40.                                         _Anim(_view, "scaleX", 1.0d, 100);
  41.                                         _Anim(_view, "svaleY", 1.0d, 100);
  42.                                     }
  43.                                 });
  44.                             }
  45.                         };
  46.                         _timer.schedule(t, (int)(100));
  47.                         break;
  48.                     }}
  49.                 return false ; }
  50.         });
  51.        
  52. ///Anim
  53. ObjectAnimator oa = new ObjectAnimator();
  54.                         oa.setTarget(_view);
  55.                         oa.setPropertyName(_Properti);
  56.                         oa.setFloatValues((float)_nilai);
  57.                         oa.setDuration((long)_durasi);
  58.                         oa.start();
  59.         oa.setInterpolator(new LinearInterpolator());
  60.         oa.start();
  61.        
  62. ///Radius & Color
  63. android.graphics.drawable.GradientDrawable gd = new android.graphics.drawable.GradientDrawable();
  64.         gd.setColor(Color.parseColor(_Warna));
  65.         gd.setCornerRadius((int)_Radius);
  66.         _view.setBackground(gd);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement