Android应用程序不支持多屏幕
我正在开发 Android 应用程序,我希望这个应用程序必须适合不同的屏幕尺寸和密度。我默认在res/layout中制作了files.xml文件,res/layout-small/xml文件用于支持小屏幕,如QVGA(低密度),res/layout-normal/xml文件用于支持中屏幕,如HVGA(中密度)和 res/layout-large/xml 文件用于大屏幕,例如 WVGA800(高密度)。当我最初在中等尺寸屏幕(例如 320x480 即 HVGA)上运行应用程序时,它运行完美,但是当我在大或小屏幕模拟器上运行相同的应用程序时,它显示与中等尺寸屏幕上显示的相同布局,并且不适合屏幕,反之亦然。反之亦然。我没有使用绝对布局,而是使用 dp 而不是 px 或 sp 或 dial。我已经尝试了很多但未能成功。我应该如何处理这种情况?有什么想法吗?
I am working on android app, i want that this app must fit on different screen sizes and densities. I have made files.xml files in res/layout by default, res/layout-small/xml files for supporting small screens such as QVGA (low density) ,res/layout-normal/xml files for supporting medium screens such as HVGA(medium density) and res/layout-large/xml files for large screens such as WVGA800(high density). When i run app initially on medium size screen such as 320x480 i-e HVGA it runs perfectly but when i run same app on large or small screen emulator it displays same layouts which were displayed on medium size screen and doesn't fit on the screen and vice versa. I havn't use absolute layout and used dp instead of px or sp or dip. I have tried alot but couldn't succeded. How should i handle that situation? Any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
需要尝试的一些事情,
在运行时转储实际屏幕尺寸以确认屏幕尺寸是您期望的尺寸获取屏幕尺寸(以像素为单位)
暂时删除 res/layout 文件夹的内容 暂时删除 res/layout 文件夹的内容,以调试从何处提取资源。
一般来说,您应该能够使用相同的布局资源但可调整宽度和高度(例如 fill_parent 等)来支持 QVGA 和 HVGA。然后为平板电脑提供单独的布局。
A few things to try,
Dump the actual screen size at run time to confirm the screen size is what you are expecting see Get screen dimensions in pixels
Temporarily remove the contents of the res/layout folder to debug where the resources are being pulled from.
Generally you should be able to support QVGA and HVGA with the same layout resource but adaptable widths and heights, eg fill_parent etc. Then have a seperate layout for tablets.