0
我有imageView。 ImageView具有圖像。當我移動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;
}
});
它working..thanks – user2474320
如何使用此代碼裏面捏? – user2474320