Interactive Android Animation

396 views Asked by At

I am trying to implement an interaction-animation in android where the user can change the size of object and rotate it with interaction.

enter image description here

This is not exactly what I am trying to implement, but something similar.

I want to allow the user to change the angle line 'p' and with that the angle 'a' should change. Moving 'p' w.r.t center should allow the size of the shape to change.

I have already tried, Animation and Animator Classes but they don't fully serve the purposes.

I am not asking for any code, I just need a pointer on ho I can implement that.

1

There are 1 answers

1
Shane Duffy On BEST ANSWER

As far as I can tell, you want the line, circle, and 'a' labelled arc to change with respect to 'p', which would be where the user touches.

The Line

This part is relatively simple, presuming you are already aware of how to acquire the X and Y coordinates that the user clicks. Firstly, you'll need to override the onDraw method, which will provide you with a canvas element that you can draw on. Then, when the user touches the screen, you can very easily draw a line from the center of your screen to the respective X and Y coordinates.

The Circle

This part would also be relatively simple, as Canvas also has a drawCircle function to easily draw a circle around a given X and Y coordinate with a specified radius. To draw a circle corresponding to the user's touch event, just use the distance function to calculate the distance from the user's touch X and Y coordinates to the center of the screen coordinate, and use this as a radius for your circle.

The Arc

Drawing an arc dynamically is relatively hard to explain and my girlfriend is nagging me to go eat dinner with her, but this question very clearly answers it, I think.

Also note that you will probably need to clear the canvas on every touch event, lest all previous drawings will begin stacking on top of each other. Cheers.