Make Screen Compatibility Containing Canvas

吃可爱长大的小学妹 提交于 2019-12-06 15:01:36

in your onDraw method you might want to check the layout height and width of your canvas and adjust your draw.height and draw.width accordingly.

If the size has increased for the screen then you can use a multiplying factor to your draw.width and draw.height constants to either multiply or divide before drawing.

EDIT: After code was posted.

Lets say 320*240 is the base case for you to draw a rectangle of height as 40 and breadth as 40 that is canvas.drawRect(10, 10, 50, 50, paint);So left, top, right and bottom can be used to be modified in your case with a new resolution of 1280*800 using the below formula.

320 --> (50 - 10)
1280 --> (x - 10)

so x = 10 + (50-10)*1280/320

Try to repeat the same forumla for wdith and you should get your base co-ordinates. I believe you can adjust your 10, 10(which I am keeping here constant) to a new location based on the same above formula.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!