I am working on an Android app where I would like the user to be able to drag their finger on the screen and have an object I have set up as an Image View (a plane) follow it. I have a somewhat working model of this right now where the image will go to a point that is touched on the screen, but this is not exactly what I am looking to do. Also each time the user touches a new point, my image goes back to its starting spot then go to the users touch point. This is the relevant code:
public boolean onTouch(View v, MotionEvent e){
switch (e.getAction()){
case MotionEvent.ACTION_DOWN:
{
}
case MotionEvent.ACTION_UP:
{
float x = e.getX();
float y = e.getY();
movePlane(x, y);
}
case MotionEvent.ACTION_MOVE:
{
}
}
return true;
}
private boolean movePlane(float endX, float endY){
ImageView plane = (ImageView) findViewById(planeID);
float startX = plane.getX();
float startY = plane.getY();
TranslateAnimation animation = new TranslateAnimation(startX, endX, startY, endY);
animation.setDuration(3000);
animation.setFillAfter(true);
animation.setFillEnabled(true);
plane.startAnimation(animation);
return true;
}
So I know I am probably going to be working inside of the ACTION_DOWN case but I am not sure exactly how I should be handling the event and ImageView accordingly. Any help is really appreciated.