I'm trying to code an app, where I'm able to move an Imageview only on a specific circular path.
@Override
public boolean onTouch(View view, MotionEvent event) {
float touchedX = 0;
float touchedY = 0;
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
break;
case MotionEvent.ACTION_UP:
break;
case MotionEvent.ACTION_POINTER_DOWN:
break;
case MotionEvent.ACTION_POINTER_UP:
break;
case MotionEvent.ACTION_MOVE:
touchedX = event.getX();
touchedY = event.getY();
float deltaX = touchedX-widthHalf;
float deltaY = touchedY-heightHalf;
double angle = Math.atan(deltaY/deltaX);
timeCircleButton.setX(widthHalf + ((float)(radius*(Math.cos(angle)))));
timeCircleButton.setY(heightHalf + ((float)(radius*(Math.sin(angle)))));
break;
}
return true;
}
This is my onTouchListener so far. HeightHalf and WidthHalf are the Coord. of the center point. I think my idea is right, but right now the ImageView is moving on a part of the circle and not on the whole circle like I want to.
So my question: Where is my fault?
If you need more information please let me know.