I have manage to draw a rectangle using the path object but I have problems adding the points into a point ArrayList. The x and y depends on the touch coordinates.
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
构造路径甚至为此创建单独的函数时使用。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.