In Android, how do I set the Rect position to X and Y?

I am trying to draw a simple Rect on a canvas that is at the X coordinate of 360, and the Y coordinate of 0. I can draw my Rect if I make the X coordinate of 0, but when I do 360, the square is distorted and becomes a rectangular shape, not the square. The screen size is 640 pixels, so there should be no problems. I can draw bitmaps with the same specifications, and it will paint fine. Why doesn't Rect draw correctly? Is it somehow that the X coordinate is only in DP, and not in PX? Then why does this affect the actual size of the rect? I'm really confused.

Rect square6 = new Rect(); square6.set(360, 0, 60, 60); 
+4
source share
1 answer

You should read the Rect link in Android, the installed Rect function is the public void set (int left, int top, int right, int bottom), you set the start of your run from (360, 0) and end with (60, 60), you must change the parma to (360, 0, 420, 60). This will work.

+6
source

Source: https://habr.com/ru/post/1445667/


All Articles