I created a custom view loading an image of a small ball. So that the onDraw method would look like this:
public void onDraw(Canvas canvas) {
canvas.drawBitmap(...);
}
Later, I added an onTouch listener to be able to listen to touch events to enable the ball to be dragged around.
public boolean onTouchEvent(MotionEvent event) {
int eventaction = event.getAction();
int X = (int)event.getX();
int Y = (int)event.getY();
switch (eventaction ) {
case MotionEvent.ACTION_MOVE: // touch drag with the ball
// move the balls the same as the finger
ball.setX(X-25);
ball.setY(Y-25);
break;
}
// redraw the canvas
invalidate();
return true;
}
Now, I am trying to make the ball move ONLY along a curve and if its not moved beyond a fixed point, make it swing back to its original position. So there are two problems I am currently facing:
- Fixing the movement path of the ball
- Flinging it back by animating it.
One problem I am observing is if I
use
ball.startAnimation
, and if the ball was slightly out of focus, the ball appears sliced.
Any suggestions please?