我在一张图片上有setOnTouchListener,它根据我的手指移动而移动。我可以根据该图像的移动调用framelayout。我们的要求就是当我将图像从上到下移动时,它应该带有该图像。
final ImageView swipedown_test = (ImageView)findViewById(R.id.swipedown);
swipedown_test.setOnTouchListener(new View.OnTouchListener()
{
@Override
public boolean onTouch(View v, MotionEvent event)
{
switch(event.getAction())
{
case MotionEvent.ACTION_DOWN:
origXCord = swipedown_test.getX();
origYCord = swipedown_test.getY();
final float x = v.getX();
final float y = v.getY();
dX = x - event.getRawX();
dY = y - event.getRawY();
mLastTouchX = x;
mLastTouchY = y;
System.out.println("original x value :" +x);
System.out.println("Original y Value :" +y);
break;
case MotionEvent.ACTION_MOVE:
// Want here to show framelayout with this image
final float x1 = v.getX();
final float y1 = v.getY();
System.out.println("On moveStart X Value :" +x1);
System.out.println("On moveStart Y Value :" +y1);
// Calculate the distance moved
final float dx1 = x1 - mLastTouchX;
final float dy1 = y1 - mLastTouchY;
System.out.println("movement in x : "+dx1);
System.out.println("Movement in y : "+dy1);
v.setY(event.getRawY() + dY);
v.setX(event.getRawX() + dX);
break;
case MotionEvent.ACTION_UP:
v.setX(origXCord);
v.setY(origYCord);
break;
default:
break;
}
return true;
}
});