简体   繁体   English

互动Android动画

[英]Interactive Android Animation

I am trying to implement an interaction-animation in android where the user can change the size of object and rotate it with interaction. 我正在尝试在android中实现交互动画,用户可以在其中更改对象的大小并通过交互旋转它。

在此输入图像描述

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. 我想让用户改变角度线'p',并且角度'a'应该改变。 Moving 'p' wrt center should allow the size of the shape to change. 移动'p'wrt中心应该允许形状的大小改变。

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. 我不是要求任何代码,我只需要一个指针就可以实现。

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. 据我所知,你希望线条,圆圈和'a'标记的弧相对于'p'改变,这将是用户触摸的位置。

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. 这部分相对简单,假设您已经知道如何获取用户点击的X和Y坐标。 Firstly, you'll need to override the onDraw method, which will provide you with a canvas element that you can draw on. 首先,您需要覆盖onDraw方法,该方法将为您提供可以绘制的canvas元素。 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. 然后,当用户触摸屏幕时,您可以非常轻松地从屏幕中心绘制一条线到相应的X和Y坐标。

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. 这部分也相对简单,因为Canvas还有一个drawCircle函数,可以在指定半径的给定X和Y坐标周围轻松绘制一个圆。 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. 要绘制与用户触摸事件对应的圆,只需使用距离函数计算用户触摸X和Y坐标到屏幕坐标中心的距离,并将其用作圆的半径。

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. 干杯。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM