简体   繁体   中英

Android screen coordinate system : how to set (0,0) at the bottom left side of android screen as first quadrent of xy plane

如何设置Android屏幕的屏幕坐标系作为XY平面的第一象限,我想知道(0,0)位置是否在左下角,我想知道我是否可以在android屏幕上使用trignometric方程作为Android XY平面不像Xy飞机

I don't think there's a way to do it that would affect the entire system, such as the XML layout files. But if you just want to draw with a Canvas , you can use translate() and scale() .

First use translate() to slide the canvas down so 0,0 is at the bottom. Now the top of the screen would be a negative number, so call scale() to flip it around. Now 0,0 is still at the bottom, and the top of the screen is a positive number.

I'm working with information from this answer and its comments . Use something like:

canvas.save();                            // need to restore after drawing
canvas.translate(0, canvas.getHeight());  // reset where 0,0 is located
canvas.scale(1, -1);                      // invert
...                                       // draw to canvas here
canvas.restore();                         // restore to normal

And yes, you can use normal 2D trigonometric functions with the XY coords. You can do it even if they're not translated, you just have to think it through more carefully.

I don't know that you're going to have much luck changing where (0,0) is located, but you could set a constant that accounts for such. myY = y minus screenHeight so (x, myY) adjusts y to the bottom of the screen and works from there +/-.

look up canvas.scale(xs,ys,xp,yp)

xp and yp are the new coordinates that you set for your (0,0) point.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM