开发者

Scaling Android Canvas 2D graphics for different devices

开发者 https://www.devze.com 2023-02-11 03:38 出处:网络
I asked a similar question to this awhile back and got zero responses, so I\'m going to try rephrasing it . . .

I asked a similar question to this awhile back and got zero responses, so I'm going to try rephrasing it . . .

开发者_如何学C

What is "best practice" for ensuring that the 2D drawing primitives in the Canvas class scale properly for different devices (phones with different screen resolutions)? Are they supposed to scale automatically? Is there a way to scale the whole canvas? Am I supposed to detect the size and do my own scaling as I draw each line, circle and point individually? Am I supposed to do it by manipulating the View? Or what?

The goal is to make sure the graphics fill up the screen to take full advantage of the available resolution, but don't overflow it.

Thanks in advance!


The way I do it in my app is by keeping track of the size of my View:

@Override 
protected void onSizeChanged(int width, int height, int oldw, int oldh) {
  //do some calculations with width and height
}

Then whenever I need to manually draw something, I do it in terms of a percentage of the total resolution. Your mileage may vary depending on exactly what you are trying to do.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号