我有图像视图。ImageView 有图像。当我移动 imageView 时,图像没有正确移动。我参考了其他一些教程,但没有帮助。当我将图像向左移动时,它会向下移动
代码:
imageView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
layoutParams = (RelativeLayout.LayoutParams) imageView.getLayoutParams();
switch(event.getAction())
{
case MotionEvent.ACTION_DOWN:
break;
case MotionEvent.ACTION_MOVE:
int x_cord = (int) event.getRawX();
int y_cord = (int) event.getRawY();
System.out.println("value of x" +x_cord);
System.out.println("value of y" +y_cord);
if (x_cord > windowwidth) {
x_cord = windowwidth;
}
if (y_cord > windowheight) {
y_cord = windowheight;
}
layoutParams.leftMargin = x_cord+25;
layoutParams.rightMargin = y_cord+25;
imageView.setLayoutParams(layoutParams);
break;
default: break;
}
return true;
}
});