这是如何完成的.假设你有点,使这些全局:
PointF topLeft = new PointF(10,10);
PointF topRight = new PointF(90,10);
PointF bottomLeft = new PointF(10,90);
PointF bottomRight = new PointF(90,90);
你需要做的是在每个点周围做一个RectF. RectF越大,触摸面积就越大.
float sizeOfRect = 5f;
RectF topLeftTouchArea = new RectF(topLeft.x - sizeOfRect, topLeft.y - sizeOfRect, topLeft.x + sizeOfRect, topLeft.y + sizeOfRect);
//Do this for the other points too
定义一些全局变量来跟踪用户在onTouch中的操作.一个int是被触摸的角落,另外四个是角落的标识符.
private final int NONE = -1, TOUCH_TOP_LEFT = 0, TOUCH_TOP_RIGHT = 1, TOUCH_BOT_LEFT = 2, TOUCH_BOT_RIGHT = 3;
int currentTouch = NONE;
现在,在您的onTouch事件中,您可以检查用户感兴趣的点,如下所示:
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
//The user just p