android imageview按鈕按下動畫效果


  private ImageView today_eat;

  today_eat = (ImageView) view.findViewById(R.id.today_eat);
  today_eat.setOnClickListener(b);
  today_eat.setOnTouchListener(b);

onTouch里面寫動畫事件

public boolean onTouch(View v, MotionEvent event) {
if (v.getId() == R.id.today_eat) {
if (event.getAction() == MotionEvent.ACTION_UP) {
ObjectAnimator oa = ObjectAnimator.ofFloat(today_eat,
"scaleX", 0.93f, 1f);
oa.setDuration(500);
ObjectAnimator oa2 = ObjectAnimator.ofFloat(today_eat,
"scaleY", 0.93f, 1f);
oa2.setDuration(700);
oa.start();
oa2.start();
}
if (event.getAction() == MotionEvent.ACTION_DOWN) {
ObjectAnimator oa = ObjectAnimator.ofFloat(today_eat,
"scaleX", 1f, 0.93f);
oa.setDuration(500);
ObjectAnimator oa2 = ObjectAnimator.ofFloat(today_eat,
"scaleY", 1f, 0.93f);
oa2.setDuration(700);
oa.start();
oa2.start();
}
} else if (v.getId() == R.id.tomorrow_eat) {
if (event.getAction() == MotionEvent.ACTION_UP) {
ObjectAnimator oa = ObjectAnimator.ofFloat(tomorrow_eat,
"scaleX", 0.93f, 1f);
oa.setDuration(500);
ObjectAnimator oa2 = ObjectAnimator.ofFloat(tomorrow_eat,
"scaleY", 0.93f, 1f);
oa2.setDuration(700);
oa.start();
oa2.start();
}
if (event.getAction() == MotionEvent.ACTION_DOWN) {
ObjectAnimator oa = ObjectAnimator.ofFloat(tomorrow_eat,
"scaleX", 1f, 0.93f);
oa.setDuration(500);
ObjectAnimator oa2 = ObjectAnimator.ofFloat(tomorrow_eat,
"scaleY", 1f, 0.93f);
oa2.setDuration(700);
oa.start();
oa2.start();
}
}
return false;
}
}

  

  

 阿里巴巴圖庫


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM