Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/315.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
Java 如何从ArrayList获取点值_Java_Android - Fatal编程技术网

Java 如何从ArrayList获取点值

Java 如何从ArrayList获取点值,java,android,Java,Android,我有一个小问题,我希望很容易解决。在下面第二行的代码中,我有path1.moveTo…,但我认为最好使用接触点[0]的X和Y的第一个值,而不是使用接触点x1和1坐标,但我不知道如何使用 // Path 1 path1.moveTo(touchDownX1, touchDownY1); for(Point point: touchPoints[0]) { path1.lineTo(point.x, point.y); canvas.drawPath(path1, paint1); } 您必须编写

我有一个小问题,我希望很容易解决。在下面第二行的代码中,我有
path1.moveTo…
,但我认为最好使用
接触点[0]
X
Y
的第一个值,而不是使用
接触点x1
1
坐标,但我不知道如何使用

// Path 1
path1.moveTo(touchDownX1, touchDownY1);
for(Point point: touchPoints[0]) {
path1.lineTo(point.x, point.y);
canvas.drawPath(path1, paint1);
}

您必须编写
接触点。获取(0)
,因为
[index]
符号仅适用于数组,而不适用于数组列表

编辑: 代码的其余部分应该可以工作。假设第一个元素接触点是一个点列表,那么访问x和y的方式非常好。如果接触点的第一个元素是单点,不要使用循环,只需执行
touchPoints.get(0).x
和y的相同操作

编辑:
只能在轮廓/形状的开始处调用
moveTo
方法来设置其起点。对于单个轮廓,没有理由将其称为更高的值。

谢谢您的回答!是的,但我想我还必须写:touchPoints.get(0).x??如果你没有使用for循环遍历touchPoints的第一个元素中的点,你应该只写
touchPoints.get(0).x
。好的,但我想我必须像我一样开始绘制路径。你想为arrayList中的所有点绘制点吗?或者只是数组中的第一个点?我想我必须使用path1.moveTo。。。。开始画线,然后画线的其余部分??还有更好的方法吗?我看不出只画第一个点就画一个循环有什么意思。@ZouZou在循环中,我在手指在屏幕上移动的时候画出剩下的路径