简体   繁体   English

在Android中,如何给Rect一个X和Y位置?

[英]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.

相关问题 如何获得拖动的释放X和Y位置? - How do I get the release X and Y position of a Drag? 如何将AbsoluteLayout中的ImageView移动到XY位置 - How do I move an ImageView in AbsoluteLayout to X Y position 在Android上,如何绘制像pygame Rect这样的Rect? (x,y,w,h) - On Android, how to draw a Rect like pygame Rect? (x, y, w, h) 如何在 Android 上使用 x 和 y position 获取视图 - How to get view with x and y position on Android 关于Android:当我使用onTouchEvent()时,如何使用Log获取位置(x,y)? - About Android: how to use Log to gain the position (x,y) when I use the onTouchEvent()? 如何将多个对象的x,y,z坐标转换为显示这些对象位置的Android应用程序? - How could I turn coordinates x,y,z coordinates of several objects into an Android app that displays the position of these objects? 我如何在 android 中使用 xy position 在图像上制作可移动的小点? - How i make movable perticuler dots on image with x y position in android? 在Android中放大后如何获取视图的xy位置 - How to get the x y position of a view after zoom-in in android android - 如何在imageview中获取图像边缘x / y位置 - android - how to get the image edge x/y position inside imageview 如何在android TextView中获取点击跨度的x,y位置? - How to get x,y position of clicked span in android TextView?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM