Interactive animation for Android

I am trying to implement an interaction animation in android, where the user can resize the object and rotate it using the interaction.

enter image description here

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

I want to allow the user to change the angular line 'p' and so that the angle 'a' should change. Moving the center of the 'p' wrt should allow you to resize the form.

I've already tried animation and animator classes, but they don't fully serve the purpose.

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

+6
source share
1 answer

As far as I can tell, you want the line, circle and "a" to be marked with an arc to change with respect to "p", which will be where the user touches.

Line

This part is relatively simple, assuming that you already know how to get the X and Y coordinates that the user clicks. First, you need to override the onDraw method, which will provide you with a canvas to draw on. Then, when the user touches the screen, you can easily draw a line from the center of your screen to the corresponding X and Y coordinates.

A circle

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

Arc

Drawing an arc is dynamically relatively difficult to explain, and my friend forces me to go to dinner with her, but this question answers this very clearly, I think.

Also note that you will probably need to clear the canvas of each touch event so that all previous drawings do not begin to stack on top of each other. Greetings.

+1
source

Source: https://habr.com/ru/post/1013814/


All Articles