我试图在屏幕上画出两个点&当我触摸point1并将其拖到point2时,需要从point1绘制一条线到point2。
如下图所示
答案 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