Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/202.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在垂直位置绘制点&;用手指在这些点之间画一条线?_Android_Android Canvas_Android Drawable - Fatal编程技术网

Android 如何在垂直位置绘制点&;用手指在这些点之间画一条线?

Android 如何在垂直位置绘制点&;用手指在这些点之间画一条线?,android,android-canvas,android-drawable,Android,Android Canvas,Android Drawable,我试图在屏幕上画两个点&当我触摸点1并将其拖动到点2时,需要从点1到点2画一条线 如下图所示 遵循此代码触摸事件进行拖动 @Override public boolean onTouchEvent (MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { start_x = event.getX(); start_y = event.getY(); } else if

我试图在屏幕上画两个点&当我触摸点1并将其拖动到点2时,需要从点1到点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

  }
对于绘制线,请遵循此链接

对于本例,我需要扩展活动或视图?您需要扩展活动并实现OnTouchlistner