开发者

Change size of rectangle by dragging its corners in Android?

开发者 https://www.devze.com 2023-02-12 02:56 出处:网络
http://farm3.anhso.net/upload/20110221/12/o/anhso-121531_example.jpg Here is the examples, when you开发者_JAVA百科 drag A or B , the size of rectangle will be changed

http://farm3.anhso.net/upload/20110221/12/o/anhso-121531_example.jpg

Here is the examples, when you开发者_JAVA百科 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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号