简体   繁体   English

针对不同屏幕尺寸的Android处理程序

[英]Android handler for different screen sizes

I need to know how my game can handle all these screen sizes i have seen a few options including: 我需要知道我的游戏如何处理所有这些屏幕尺寸我已经看到了一些选项,包括:

  • Re sizing the elements to fit the screen 重新调整元素大小以适应屏幕
  • Making assets in lots of different sizes 制作大量不同尺寸的资产

  • I'd like to know which is more efficient ? 我想知道哪个更有效率?

  • What are my other options ? 我还有什么其他选择?
  • How would i go about making it work ? 我将如何使它工作?

So far i am just making my screen fit to the android device i'm testing on and this could lead to failure in the future if i do not set this handler up 到目前为止,我只是让我的屏幕适合我正在测试的Android设备,如果我不设置此处理程序,这可能导致将来失败

Thanks 谢谢

well if you are using libgdx then you dont have to worry about screen sizes. 好吧,如果你使用libgdx,那么你不必担心屏幕尺寸。 just use its camera class and set its viewports accordingly . 只需使用其相机类并相应地设置其视口。 refer this link for camera 请参阅此链接以获取相机

Also you dont need to make android handlers for it. 你也不需要为它制作android处理程序。

This website talks about how to handle this problem http://developer.android.com/guide/practices/screens_support.html . 本网站讨论如何处理此问题http://developer.android.com/guide/practices/screens_support.html

It claims the best practices are: 它声称最佳做法是:

  1. Use wrap_content, fill_parent, or dp units when specifying dimensions in an XML layout file 在XML布局文件中指定维度时,请使用wrap_content,fill_parent或dp单位
  2. Do not use hard coded pixel values in your application code 请勿在应用程序代码中使用硬编码像素值
  3. Do not use AbsoluteLayout (it's deprecated) 不要使用AbsoluteLayout(不推荐使用)
  4. Supply alternative bitmap drawables for different screen densities 为不同的屏幕密度提供替代位图drawable

The problem is not with the dimensions of the screen, rather the density of the screens. 问题不在于屏幕的尺寸,而在于屏幕的密度。 Using dp to set the size for elements is the most common way. 使用dp设置元素的大小是最常用的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM