通过拖动其角在Android中更改矩形的大小?矩形、拖动、大小、Android

2023-09-05 10:33:27 作者:一走不回头

下面的例子,当你拖动A或B,矩形的大小将被改变。

Here is the examples, when you drag A or B , the size of rectangle will be changed

我怎样才能做到这一点?

How can i do it?

推荐答案

它相当简单。我假设有在你的布局只是一个单一视图。这使得一些事情变得更加简单。

Its fairly simple. Let me assume that there is only a single view in your layout. This makes a few things a lot easier.

当您收到触碰动作,必须检查,其中在考虑到这一点的所在。矩形的坐标明明知道你。也明白,你需要触摸A附近或B触仅意是precise。但实际上它不是。所以,你必须创建一个在附近,你会接受触摸要在规定点。

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.

如果触摸点在A或B的附近,应设置将在触摸移动动作被检查的标志。存储的每一个点在某种参考变量的触摸或移动时是个好主意辩论,因为那么你可以得到当前点从一个已知点(如手指触摸的时刻)的位移(这是前触及 - 你参照点)。

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).

使用该差值(△沿x和y),你就可以改变该矩形的长度和高度。无效更改这些参数后视图。矩形再次绘制,它会看起来像的尺寸发生了变化。

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.