问题
I'm making a game with a board and an object that travels around the board. At this point, I have been using absolute layout and setting the board to the size I want and the object to the position on the board that I want. I understand, however, that this is not the best way to write these apps. How can I make my app suitable for all smartphones still having the flexibility of making the board the size I want and putting an object exactly where I want on the board? Should I make separate xml files for each screen size (HD, WVGA, etc?)? Which layout type do you recommend using? Thanks!
回答1:
I'd highly recommend that instead of writing the game framework yourself, and using something like an AbsoluteLayout, you use one of the many game frameworks that already exist, and have multiple ways of dealing with this issue. Instead of using an AbsoluteLayout, and positioning things on the screen, you should be using a framework that wraps low-level openGL calls, and is capable of getting 60+ frames per second. For Android, I highly recommend libGDX which has a large amount of community support, and high performance.
libGDX will allow you to make an Android app, a Desktop app (wonderful for developing, as you can just start it and test your code in less than a second), and a HTML5 app that runs in a browser. (Also if you want, there are ways to compile it for iphone, but I've never tried).
Using libGDX there are a few ways to tackle the problem you are talking about (it's a common one). You can show more content if you wish for bigger screens with slightly different aspect ratios, you can stretch the screen to fit it, or you can introduce black bars for slightly different aspect ratios as well, all of which can be done easily as you are setting up your view.
If your interested, there are plenty links to tutorials and documentation on their main site.
Edit: Here is a question dealing with multiple screen resolutions for libGDX: Dealing with different aspect ratios in libgdx
回答2:
for games, you should consider using games libraries.
2 of the popular libraries i know of are libGdx and AndEngine.
each has its own advantages and disadvantages.
from my experience, LibGdx is harder to learn and is more low level than AndEngine, but it has higher performance and can run cross platform (even on your own PC) .
AndEngine is based on LibGdx, so it gets some of its advantages, but it's not the same.
another possible solution would be to learn openGL ES and do everything on your own. currently, about 99% of the devices have openGL ES 2 , so maybe learn it instead of openGL ES 1.
来源:https://stackoverflow.com/questions/17936574/compatibility-of-android-screens