Change size of rectangle by dragging its corners in Android?

拟墨画扇 提交于 2020-01-01 15:29:25

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/5065077/change-size-of-rectangle-by-dragging-its-corners-in-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!