简体   繁体   English

从ArrayList Android上的路径对象存储点

[英]Storing points from a path objects on a ArrayList Android

I have manage to draw a rectangle using the path object but I have problems adding the points into a point ArrayList. 我设法使用path对象绘制一个矩形,但是在将点添加到点ArrayList中时遇到问题。 The x and y depends on the touch coordinates. x和y取决于触摸坐标。

Here is my code: 这是我的代码:

public static ArrayList<ArrayList<Point>> pList = new ArrayList<ArrayList<Point>>();

public void addRectangle() {

    Path path = new Path();

    path.moveTo(x, y);
    path.lineTo(x+25, y);
    path.lineTo(x+25, y+5);
    path.lineTo(x, y+5);

    path.close();

    pList.add(?);// what do i put over here?

}

Please advice. 请指教。 Thank you. 谢谢。

List<Point> points = new ArrayList<Point>();

Point pointOne = new Point(x,y);
Point pointTwo = new Point(x+25,y);
Point pointThree = new Point(x+25,y+5);
Point pointFour = new Point(x,y+5);
points.add(pointOne );
points.add(pointTwo );
points.add(pointThree );
points.add(pointFour);



Path path = new Path();
path.moveTo(pointOne.x, pointOne.y);
path.lineTo(pointTwo.x, pointTwo.y);
//and so on
path.close();

//and then
pList.add(points); 

由于无法迭代Path ,因此最好将其用作输出性质的对象,因此,基本上,您首先应该在点上填充ArrayList ,并在使用此ArrayList构造路径甚至为此创建单独的函数时使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM