标签:
//给image设置手指触摸的监听器
iv.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
//判断当前手指事件的类型
//按下 移动 离开
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:// 手指按下屏幕
System.out.println("action down");
break;
case MotionEvent.ACTION_MOVE:// 手指在屏幕上移动
int x = (int) event.getX();
int y = (int) event.getY();
System.out.println("设置("+x+","+y+")透明颜色");
for(int i=-4;i<5;i++){
for(int j=-4;j<5;j++){
try{
//让手指经过的地方图片变成透明
//try是为了让鼠标超出图片之后就没有效果了
alertBitmap.setPixel(x+i, y+j, Color.TRANSPARENT);
}catch (Exception e) {
// TODO: handle exception
}
}
}
iv.setImageBitmap(alertBitmap);
break;
case MotionEvent.ACTION_UP:// 手指离开屏幕
//播放音乐的代码
MediaPlayer.create(getApplicationContext(), R.raw.higirl).start();
break;
}
//true认为事件处理完了,可以进行下个事件
//false是以为没有处理完,相当于直接暂停了,处理代码失效了
return true;//可以重复循环的处理事件
}
});
标签:
原文地址:http://my.oschina.net/u/2356176/blog/421042