在Android中通过拖动矩形的角来改变矩形的大小?
http://farm3.anhso.net/upload/20110221/ 12/o/anhso-121531_example.jpg
这是示例,当您拖动 A 或 B 时,矩形的大小将发生变化,
我该怎么做?
http://farm3.anhso.net/upload/20110221/12/o/anhso-121531_example.jpg
Here is the examples, when you drag A or B , the size of rectangle will be changed
How can i do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它相当简单。让我假设您的布局中只有一个视图。这使得一些事情变得容易多了。
当您收到着陆动作时,您必须检查该点位于视图上的位置。矩形的坐标显然你是知道的。还要了解您需要触摸 A 或 B 附近。准确地说,触摸只是“有意”的。但实际上并非如此。因此,您必须创建一个附近,您将在该附近接受指定点的触摸。
如果触摸点位于 A 或 B 附近,则应设置一个标志,该标志将在触摸移动操作中进行检查。将触摸或移动的每个点存储在某种参考变量中是一个好主意,因为这样您就可以获得当前点(手指当前触摸的位置)相对于最后一个已知点(之前触摸过的点)的位移 - 您的参考点)。
利用这个差异(沿 x 和 y 的增量),您将能够改变矩形的长度和高度。更改这些参数后使视图无效。再次绘制矩形,看起来尺寸已经改变。
Its fairly simple. Let me assume that there is only a single view in your layout. This makes a few things a lot easier.
When you receive a touch down action, you must check where on the view this point lies. the coordinates of the rectangle are obviously known to you. Also understand that you need to touch in the vicinity of A or B. Touch is only "intended" to be precise. But in actuality its not. So you must create a vicinity over which you will accept the touch to be at the stipulated point.
If the touched point is in the vicinity of A or B, you should set a flag which will be checked for in the touch move action. Storing every point touched or moved upon in some sort of reference variable is a good idea, cuz then you can get the displacement of the current point (where finger is touching at the moment) from the last known point (that was touched before - your reference point).
using this difference (delta along x and y) you will be able to alter the length and height of the rectangle. Invalidate the view after changing these parameters. The rectangle is drawn again and it will seem like the dimensions have changed.