1.点击后放大缩小实现
Android的事件:onClick, onScroll, onFling等等,都是由许多个Touch组成的。其中Touch的第一个状态肯定是ACTION_DOWN, 表示按下了屏幕。之后,touch将会有后续事件
对控件进行设置点击事件
findViewById(R.id.layout_click).setOnTouchListener(this);
findViewById(R.id.layout_click).setOnClickListener(this);
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN: //
if(v.getId()==R.id.layout_click){
Animation animation=new ScaleAnimation(1.0f, 0.9f, 1.0f, 0.9f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
animation.setDuration(100);
animation.setFillAfter(true);
v.startAnimation(animation);
}
break;
case MotionEvent.ACTION_UP: //
if(v.getId()==R.id.layout_click){
Animation animation=new ScaleAnimation(0.9f, 1.0f, 0.9f, 1.0f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
animation.setDuration(100);
animation.setFillAfter(true);
v.startAnimation(animation);
}
break;
default:
break;
}
return false;
}