iv.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// AB| = √[(x₁-x₂)²+(y₁-y₂)²],换成x₂-x₁和y₂-y₁
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
if ((event.getX() > -width / 2 || event.getX() < width / 2)
&& (event.getY() < -height / 2
|| event.getY() >height / 2)) {
stoptdonghua();
}else{
stoptdonghua();
}
break;
case MotionEvent.ACTION_UP:
if ((event.getX() > -width / 2 || event.getX() < width / 2)
&& (event.getY() < -height / 2
|| event.getY() > height / 2)){
stoptdonghua();
}else{
stoptdonghua();
}
break;
default:
break;
}
return false;
}
});