我正在尝试在屏幕上绘制两个点,当我触摸 point1 并将其拖动到 point2 时,需要从 point1 到 point2 绘制一条线。
如下图所示
我正在尝试在屏幕上绘制两个点,当我触摸 point1 并将其拖动到 point2 时,需要从 point1 到 point2 绘制一条线。
如下图所示
按照此代码触摸事件进行拖动
@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