[英]In Android, how do I give a Rect an X and Y position?
I'm 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 to 0, but when I make it 360, the square becomes distorted and becomes a rectangular shape rather than a square anymore. 我试图在Canvas上绘制一个简单的Rect,其X坐标为360,Y坐标为0。如果我将X坐标设为0,则可以绘制Rect,但是当我将其变为360时,正方形变得扭曲,不再是正方形,而是变成矩形。 My screen size is 640px wide, so there should be no problem here.
我的屏幕尺寸为640像素,因此这里应该没有问题。 I can draw Bitmaps with the same specifications and it will draw normally.
我可以用相同的规格绘制位图,它将正常绘制。 Why is it that Rects don't draw correctly?
为什么矩形无法正确绘制? Is it somehow that the X coordinate is only in DP rather than PX?
X坐标仅在DP中而不是PX中以某种方式存在吗? Then why does that affect the actual size of the Rect?
那为什么会影响Rect的实际大小呢? I'm really confused.
我真的很困惑
Rect square6 = new Rect();
square6.set(360, 0, 60, 60);
You should read the reference to the Rect in Android, The set func of Rect is public void set (int left, int top, int right, int bottom), you set your rect start from (360, 0) and ends at (60, 60), you should change the parmas to (360, 0, 420, 60). 您应该阅读Android中对Rect的引用, Rect的set func是public void set(int左,int顶部,int右,int底部),您将rect设置为(360,0),结束于(60 ,60),则应将Parma更改为(360,0,420,60)。 It will work.
它会工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.