I am trying to make an app using canvas and a surfaceview, and I am worrying that in the future I would have many problems with it because I am not sure if the canvas is proportional with every device. currently I can only use my emulator since my phone's usb cable doesn't work(I know.. I have to get a new one..).
anyways, i would like to know if the canvas would transfer my coordinates and make everything proportional, what I mean by that is that if i have something in point a, lets say (10, 10) on a device that the screen of it is 100 X 100 (this is just an example for easy calculation) it would be on point (1, 1) on a 10 X 10 device.
This is really bothering me...
Thanks!
No, this wouldn't be the case. If you have a coordinate (10,10), it would be the same on all devices. I'd suggest you
scale
your drawings.To
scale
your drawings you simply define a bitmap (that will stay the same) you'd like to draw to (when screen sizes change, that bitmap will be stretched).Define a constant bitmap:
Get the scale for both x and y
Define a canvas object based on the bitmap you defined earlier on (allowing you to draw to it eg. canvas.drawRect() [...]):
In your rendering Thread you'll have to have a Canvas called frameBuffer, which will render the virtual framebuffer:
No, the unit on the screen (whether you are using
canvas
orOpenGL
) is a pixel. You can get the size of your canvas usingCanvas.getWidth()
andCanvas.getHeight()
if you need relative coordinates, but your Canvas drawing methods are also in Pixels, so I guess you will need to convert coordinates inOpenGL
only and not while usingCanvas
.