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);
Storing points from a path objects on a ArrayList Android
Question
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.
Solution
OTHER TIPS
Since Path
cannot be iterated you better use it as object of output nature, so basically you should initially fill ArrayList
with points and when use this ArrayList
to construct path or even create separate function for that.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow