如何在特定位置绘制点数&用手指拖动那些点之间的线条?

时间:2013-10-21 10:51:51

标签: android android-canvas android-drawable

我试图在屏幕上画出两个点&当我触摸point1并将其拖到point2时,需要从point1绘制一条线到point2。

如下图所示 enter image description here

1 个答案:

答案 0 :(得分:2)

按照此代码触摸事件进行拖动

@Override
public boolean onTouchEvent (MotionEvent event) {

  if (event.getAction() == MotionEvent.ACTION_DOWN) {

    start_x = event.getX();
    start_y = event.getY();     

  } else if (event.getAction() == MotionEvent.ACTION_MOVE) {

    //create the line from start_x and start_y to the current location
    //don't forget to invalidate the View otherwise your line won't get redrawn

  } else if (event.getAction() == MotionEvent.ACTION_UP) {

    //might not need anything here

  }

对于绘制线,请点击此链接 How to draw a line in android