Multiple screen resolutions/aspect ratios (games)

笑着哭i 提交于 2019-11-29 20:15:21

I can't directly answer your question, but i'd like to tell you my approach. I try not to use to use any numbers at all. Instead I try using paddings, margins and relative layouts so that my views look correctly on any phone. It also helps me to avoid creating view for different orientations.

As many people here mentioned before, my approach would also be making full use of the device-independent components, such as paddins, margins, and relativelayouts, combined with Device independet puxels.

To be quite frankly, and i hope i'm not the only one, but making full use of DIP's (device independet pixels) and relative layouting and such...has reduced my activity layout files to 1 per activity instead of 3 different kinds for HDPI, MDPI and LDPI.

in case you're really concerned about the aspect ratio, you can always call the display properties in pixels of the device, and make appropriate layout calculations based on those figures. You can call this at the very start of the onCreate method of your first activity.

Display display = getWindowManager().getDefaultDisplay(); int displayWidth = display.getWidth(); int displayHeight = display.getHeight();

this will give you the width and height values of your hardware siplay in pixels. In my opinion, the true reason why you would choose over 3 layout types is to make sure image resolution stays sharp enough.

With these numbers you can make some internal logic, wich calculates wich type of resolution images to load in certain widgets. Thus saving you the trouble of making 3 times the same layout....

maybe explained a little cryptic, but the main thing to overcome the various device resolutions is to work a lot with:

  • relativelayouts
  • Device independent Pixels

you can also define DIP's in the XML layout, so every component looks the same at every type of device.

maybe a stupid Example, but hey, it worked for me :-) here below i tried to get the text size on a textview to be relatively the same on all devices. You can call the 'TypedValue'class, and select from one of the many public variables offered there. As i wanted to make the TextView everywhere the same relative size, i used the code below :

someTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);

the number is to set how big the size in DIP's should be. TypedValue can be used in many widget or activity compoents that require an INT value for dimensional properties. Play with that and you will see it makes life a lot easier :-p

hope this answer helps a bit

I found a clear answer to the problem.

Minimum resolutions are undefined prior to 3.0. So for 3.0 and above it will be possible to choose a minimum resolution, design a game based on it and grow the layout dynamically on larger screens/ratios as mentioned by superM and others.

As you design your UI for different screen sizes, you'll discover that each design requires a minimum amount of space. So, each generalized screen size above has an associated minimum resolution that's defined by the system. These minimum sizes are in "dp" units—the same units you should use when defining your layouts—which allows the system to avoid worrying about changes in screen density.

  • xlarge screens are at least 960dp x 720dp
  • large screens are at least 640dp x 480dp
  • normal screens are at least 470dp x 320dp
  • small screens are at least 426dp x 320dp

Note: These minimum screen sizes were not as well defined prior to Android 3.0, so you may encounter some devices that are mis-classified between normal and large. These are also based on the physical resolution of the screen, so may vary across devices—for example a 1024x720 tablet with a system bar actually has a bit less space available to the application due to it being used by the system bar.

Source

There is no exhaustive list of aspect ratios. Manufacturers can decide on whatever resolution they feel like. On top of that, aspect ratios don't match up with pixel density, so using ldpi/mdpi/hdpi to decide on aspect ratio is probably not a good idea.

Your strategy for dealing with this really depends on your game. Of course to a certain extent you should simply scale everything larger/smaller, but obviously the tricky parts are the edges which are different on different aspect ratios. Certain games (first person shooters, side-scrollers, tiled top-down games, etc.) you can just provide a different field of view without too much problem as long as you're not concerned about giving an advantage to certain devices, for others you might consider having a stretchable or tileable graphic for the background, and maintain the same effective (scaled) playing area.

f20k

You can try asking in GameDev.stackexchange.com

Here is a similar problem to yours: building a game for different resoulution phones

You can limit what devices can see your game on marketplace based on screen resolution: http://developer.android.com/guide/appendix/market-filters.html

I've not delved into it fully but I can't see any mention of aspect ratio unfortunately so you might have to fill in all the ones you know will work.

Failing that, you can set a minimum resolution that you require for your graphics to look good and if you don't want to change the game for the smaller ratios, you can add black borders as they would do on console games. It's not recommended however, mobile screen space is precious enough so if you do chop the playing area with black bars, I would move your HUD into the black area so you are still using as much of the screen as possible.

There is more info on supporting screen sizes here: http://developer.android.com/guide/practices/screens_support.html

: D

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