且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Android应用程序开发中为所有类型的手机设置相同的分辨率?

更新时间:2022-01-27 01:10:18

无法完成。

即使您实现了一些缩放方法,也可以将整个UI或游戏绘制到虚拟画布上,然后缩放(向上或向下) )为适应屏幕,您仍会遇到纵横比不同的问题。



/ Fredrik
It cannot be done.
Even if you implemented some scaling-method drawing your entire UI or game to a virtual canvas that was then scaled (up or down) to fit the screen you would still run into issues with aspect ratios being different.

/Fredrik


你做不到 - 考虑一下,你会明白为什么:android在我所知道的426x320到1920x1200的设备上运行:如果你尝试使用这两款相同的分辨率,那么它们看起来都很糟糕!



什么是你试图这样做你认为这是个好主意吗?
You can't do it - think about it for a moment, and you will see why: android runs on devices from 426x320 to 1920x1200 that I know of: if you try to use is as the same resolution on those two it will look terrible on both!

What are you trying to do that you think this would be a good idea?


我想说不要为特定的分辨率设计。使用 wrap_content layout_width layout_width layout_height 值的组合来获取 wrap_content match_parent 的值不同的比例宽度取决于屏幕尺寸,而不是硬编码像素值。并且还使用 dp (与设备无关的像素),因为它也会根据密度略有变化,因此无论分辨率如何,它都保持一致的物理尺寸。

并进行以下研究:

支持多个屏幕 [ ^ ]

在设计Android应用程序时,我应该考虑哪个屏幕分辨率 [ ^ ]
I would say don't design for a specific resolution. Use combinations of layout_weight, layout_width and layout_height values of wrap_content and match_parent to get different proportional widths depending on the screen size, rather than hard coding pixel values. And also use "dp"(device-independent pixel), because it also changes slightly depending on the density, so that it stays a consistent physical size no matter what the resolution is.
And have a study with these:
Supporting Multiple Screens[^]
Which screen resolution should i consider while designing an android application[^]