我知道如何绘制两点之间的线canvas.drawline(10,10,90,paint);通过使用这个我可以绘制点之间的线.
编辑:在这里我附上图片,以清楚解释,从保罗回答现在我可以绘制点之间的线,仍然有拉点的问题…
解决方法 这是如何完成的.假设你有点,使这些全局: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事件中,您可以检查用户感兴趣的点,如下所示:
@OverrIDepublic boolean ontouchEvent(MotionEvent event) { switch (event.getAction()) { //The user just put their finger down. //We check to see which corner the user is touching //And set our global,currenttouch,to the appropriate constant. case MotionEvent.ACTION_DOWN: if (toplefttouchArea.contains(event.getX(),event.getY()) { currenttouch = touch_top_left; } else if (topRighttouchArea.contains(event.getX(),event.getY()) { currenttouch = touch_top_RIGHT; } else if (botlefttouchArea.contains(event.getX(),event.getY()) { currenttouch = touch_BOT_left; } else if (botRighttouchArea.contains(event.getX(),event.getY()) { currenttouch = touch_BOT_RIGHT; } else { return false; //Return false if user touches none of the corners } return true; //Return true if the user touches one of the corners //Now we kNow which corner the user is touching. //When the user moves their finger,we update the point to the user position and invalIDate. case MotionEvent.ACTION_MOVE: switch (currenttouch) { case touch_top_left: topleft.x = event.getX(); topleft.y = event.getY(); //The bottom left x position has to move with the top left corner bottomleft.x = topleft.x; //The top right y position has to move with the top left corner topRight.y = topleft.y; invalIDate(); return true; case touch_top_RIGHT: topRight.x = event.getX(); topRight.y = event.getY(); //The top left y position has to move with the top right corner topleft.y = topRight.y; //The bottom right x position has to move with the top right corner bottomright.x = topRight.x; invalIDate(); return true; case touch_BOT_left: bottomleft.x = event.getX(); bottomleft.y = event.getY(); bottomright.y = bottomleft.y; topleft.x = bottomleft.x; invalIDate(); return true; case touch_BOT_RIGHT: bottomright.x = event.getX(); bottomright.y = event.getY(); topRight.x = bottomright.x; bottomleft.y = bottomright.y; invalIDate(); return true; } //We returned true for all of the above cases,because we used the event return false; //If currenttouch is none of the above cases,return false //Here the user lifts up their finger. //We update the points one last time,and set currenttouch to NONE. case MotionEvent.ACTION_UP: switch (currenttouch) { case touch_top_left: topleft.x = event.getX(); topleft.y = event.getY(); //The bottom left x position has to move with the top left corner bottomleft.x = topleft.x; //The top right y position has to move with the top left corner topRight.y = topleft.y; invalIDate(); currenttouch = NONE; return true; case touch_top_RIGHT: topRight.x = event.getX(); topRight.y = event.getY(); //The top left y position has to move with the top right corner topleft.y = topRight.y; //The bottom right x position has to move with the top right corner bottomright.x = topRight.x; invalIDate(); currenttouch = NONE; return true; case touch_BOT_left: bottomleft.x = event.getX(); bottomleft.y = event.getY(); bottomright.y = bottomleft.y; topleft.x = bottomleft.x; invalIDate(); currenttouch = NONE; return true; case touch_BOT_RIGHT: bottomright.x = event.getX(); bottomright.y = event.getY(); topRight.x = bottomright.x; bottomleft.y = bottomright.y; invalIDate(); currenttouch = NONE; return true; } return false; }}
这是做一个围绕你的点的矩形.想像一下在图片周围的绘图框.这些是由Rect对象创建的“触摸板”.矩形的大小由sizeOfRect设置.在ontouchEvent中,它检查每个矩形对象以查看用户的触摸是否在矩形内,从而指示用户尝试触摸该点.
总结以上是内存溢出为你收集整理的android – 如何在点之间画一条线,拉这些点?全部内容,希望文章能够帮你解决android – 如何在点之间画一条线,拉这些点?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)