When trying to draw using the paths (path) on the Canvas square, or several squares, they are not drawn. However, if you draw a circle using paths, it is drawn freely. How can I draw a square using paths?

Path path = new Path(); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); path.addRect(100, 200, 100, 50, Path.Direction.CW); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(5); paint.setColor(Color.GREEN); canvas.drawPath(path, paint); 

Closed due to the fact that off-topic participants 0xdb , freim , aleksandr barakin , mkkik , entithat May 14 at 19:14 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - 0xdb, freim, aleksandr barakin, mkkik, entithat
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Read more carefully in the documentation what the addRect method arguments mean - your left and right sides are the same, and the top is lower than the bottom. - woesss
  • @woesss And the difference? Anyway, the square is drawn, if next to it draw a circle with the help of path. And without a circle it is not drawn - RomatoPotato
  • Well, you do not have a difference - to me, and all the more ... Show your code that draws a square with a circle - then you can talk about the difference. The presented piece of code should draw a vertical strip 5px wide and 150px high - woesss

1 answer 1

I found why I didn’t display a square. Simply, I had the wrong API. And on the phone everything was displayed