2 回答
TA贡献1752条经验 获得超4个赞
改变这个
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
button1.setOnTouchListener(new OnTouchListener() {
PointF DownPT = new PointF();
PointF StartPT = new PointF();
@Override public boolean onTouch(View v, MotionEvent event) {
int eid = event.getAction();
switch (eid) {
case MotionEvent.ACTION_MOVE:PointF mv = new PointF(event.getX() - DownPT.x, event.getY() - DownPT.y);
button1.setX((int)(StartPT.x+mv.x));
button1.setY((int)(StartPT.y+mv.y));
StartPT = new PointF(button1.getX(), button1.getY());
break;
case MotionEvent.ACTION_DOWN : DownPT.x = event.getX();
DownPT.y = event.getY();
StartPT = new PointF(button1.getX(), button1.getY());
break;
case MotionEvent.ACTION_UP :
break;
default : break;
}
return true;
}
});
textview13.setText(message);
}
});
对此
int lastAction;
button1.setOnTouchListener(new OnTouchListener() {
PointF DownPT = new PointF();
PointF StartPT = new PointF();
@Override public boolean onTouch(View v, MotionEvent event) {
int eid = event.getAction();
switch (eid) {
case MotionEvent.ACTION_MOVE:PointF mv = new PointF(event.getX() - DownPT.x, event.getY() - DownPT.y);
button1.setX((int)(StartPT.x+mv.x));
button1.setY((int)(StartPT.y+mv.y));
StartPT = new PointF(button1.getX(), button1.getY());
lastAction = MotionEvent.ACTION_MOVE;
break;
case MotionEvent.ACTION_DOWN : DownPT.x = event.getX();
DownPT.y = event.getY();
StartPT = new PointF(button1.getX(), button1.getY());
lastAction = MotionEvent.ACTION_DOWN;
break;
case MotionEvent.ACTION_UP :
if(lastAction == MotionEvent.ACTION_DOWN){
textview13.setText(message);
}
lastAction = MotionEvent.ACTION_UP;
break;
default : break;
}
return true;
}
});
对于第二部分,您需要具有其他项目坐标的坐标,然后检查您的event.getY()或event.getX()是否在其他项目坐标的范围内。
添加回答
举报