[英]How to get Point values from ArrayList
I have a small problem that I hope is easy to solve. 我有一个小问题,希望很容易解决。 In the code below on the second row I have
path1.moveTo...
but instead of using the touchDownX1
and touchDownY1
coordinates, I thought it would be better to use the first values of X
and Y
from the touchPoints[0]
, but I don't know how? 在下面第二行的代码中,我具有
path1.moveTo...
但我认为最好使用touchPoints[0]
的X
和Y
的第一个值,而不是使用touchDownX1
和touchDownY1
坐标,但是不知道怎么办
// Path 1
path1.moveTo(touchDownX1, touchDownY1);
for(Point point: touchPoints[0]) {
path1.lineTo(point.x, point.y);
canvas.drawPath(path1, paint1);
}
You have to write touchPoints.get(0)
because the [index]
notation only works for arrays, not ArrayLists. 您必须编写
touchPoints.get(0)
因为[index]
表示法仅适用于数组,不适用于ArrayLists。
Edit: The rest of the code should work. 编辑:其余代码应正常工作。 The way you access x and y is perfectly fine, assuming that the first element touchPoints is a list of points .
假设第一个元素touchPoints是points的列表,则访问x和y的方式非常好。 If the first element of touchPoints is a single point, do not use a loop, just do
touchPoints.get(0).x
and the same for y. 如果touchPoints的第一个元素是单个点,请不要使用循环,只需对
touchPoints.get(0).x
,对y进行相同操作。
Edit: The moveTo
method should only be called for the beginning of a contour/shape to set its starting point. 编辑:仅应为轮廓/形状的起点调用
moveTo
方法以设置其起点。 There is no reason to call it more than that for a single contour. 没有什么比为单个轮廓更多地调用它了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.