gpt4 book ai didi

android - 如何在特定位置画点并用手指在点之间画线?

转载 作者:行者123 更新时间:2023-11-29 00:25:55 24 4
gpt4 key购买 nike

我正在尝试在屏幕上绘制两个点,当我触摸点 1 并将其拖动到点 2 时,需要从点 1 到点 2 绘制一条线。

如下图enter image description here

最佳答案

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

@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

关于android - 如何在特定位置画点并用手指在点之间画线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19492529/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com