我想用手指触摸移动图像。我使用相对布局。我将在ACTION_UP和ACTION_DOWN中做什么?即时使用以下代码 我想用手指触摸相对布局移动visacard。
visacard.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
int eid = event.getAction();
switch (eid) {
case MotionEvent.ACTION_DOWN:
{
int x = (int) event.getRawX();
int y = (int) event.getRawY();
break;
}
case MotionEvent.ACTION_MOVE:
{
RelativeLayout.LayoutParams mParams = (RelativeLayout.LayoutParams) visacard.getLayoutParams();
int x = (int) event.getRawX();
int y = (int) event.getRawY();
mParams.leftMargin = x - 50;
mParams.topMargin = y - 50;
visacard.setLayoutParams(mParams);
int visacard_width = visacard.getWidth() / 2;
int visacard_height = visacard.getHeight() / 2;
int i1 = x - visacard_width;
int j1 = y - visacard_height;
int k1 = visacard.getWidth();
int l1 = visacard.getHeight();
visacard.setX(i1);
visacard.setY(j1);
// visacard_width = visacard.getWidth();
// visacard_height = visacard.getHeight();
visacard_top = visacard.getTop();
visacard_left = visacard.getLeft();
visacard_right = visacard.getRight();
visacard_bottom = visacard.getBottom();
text.setX(k1);
text.setY(l1);
break;
}
case MotionEvent.ACTION_UP:
{
break;
}
default:
break;
}
return true;
}
});
如果有人知道解决方案,请告诉我。谢谢!