EDIT: Thanks for all your answers and comments. After thinking about it i would rephrase the core of the question to: "How to determine and limit the minimum resolution/ratio my game is able to run on". Because imo either the game becomes unplayable on the smallest screen/ratio (lack of detail) or supporting even the smallest screen/ratio degrades the experience for all the others significantly. Besides we do not even know what the smallest resolution is or can restrict it in any way other than disabling ldpi... which still doesn't tell us about the smallest mdpi. After all i'm not thinking about how to create a good result but about how to create a perfect result ;). Guess it's not possible (yet?).
Note: This is purely about phones not tablets Also this question is not that relevant for applications as it is for games which don't use the Android layout system.
I always found the definitions of which resolutions to expect somewhat vague. I am aware of the list in the docs.
Now my first question is if this list is complete or in other words are manufacturer allowed to use other reolutions or aspect ratios. My current approach is to view this list in terms of aspect ratios which looks something like that (Not sure if it's exact but you get the idea):
- ldpi: smallest aspect ratio 4:3
- mdpi: smallest aspect ratio 3:2
- hdpi: biggest aspect ratio 16:9



So if i want to cover a range of devices i figure out what my smallest and my biggest aspect ratios are and design the layout for the smallest while making it automatically grow to the biggest. For example if i want to support all densities i design the screens for 4:3 and make it grow to 16:9. In case i remove ldpi support i would design for 3:2. Of course this assumes there will never be an mdpi device with an aspect ratio of 4:3 which brings us back to my first question.
My preferred solution would be to indicate on the Android Market which aspect ratios my application can handle but that doesn't seem possible so far.
Does anyone have a better approach? (Keeping in mind that it's for games on phones only)
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.
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.
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
来源:https://stackoverflow.com/questions/7061258/multiple-screen-resolutions-aspect-ratios-games