简体   繁体   中英

android screen resolutions and sizes

I am currently working on an android app that is causing me some trouble. My app is heavily dependent on images that are fitted correctly to the screen they are being displayed on. Unfortunately things like the FWVGA/WVGA resolution difference 854 vs 800 is causing me some real problems, and that's aside from the other sizes/densieites and resolutions.

I don't know if I'm just missing the point here but how do I go about having my app display correctly on both the resolutions without either "squashing" my images or cutting bits off of giving me black bars etc?

There doesn't seem an immediately present solution where I can just have it display a different image automatically from the drawable folder for the right screen.

I have tried using displaymetrics but unless i have my manifest claim that it supports all screen sizes, the android OS will in fact "lie" to my app about hte current resolution.

Someone please tell me there is an easy solution.

how do I go about having my app display correctly on both the resolutions without either "squashing" my images or cutting bits off of giving me black bars etc?

IMHO, you start by revisiting your GUI design:

My app is heavily dependent on images that are fitted correctly to the screen they are being displayed on.

That does not work particularly well anywhere, IMHO. Windows (including browsers) can be sized to any desired size by the user, for example.

There doesn't seem an immediately present solution where I can just have it display a different image automatically from the drawable folder for the right screen.

Because Android devices can have any number of screen dimensions, just like windows and Web browsers can have any number of screen dimensions. Android does let you choose images based on density (eg, -hdpi ) or screen size (eg, -large ), but these do not map to resolutions, nor should they.

As CommonsWare pointed out, your best bet for this situation really is to rethink your layout structure. It's probably possible to accomplish similar, if not identical results to what you currently have, using RelativeLayouts and widgets. If you're willing to post a sample, we could advise you on ways to do so.

That said, an answer to your question would be to query the device at runtime for its screen resolution (keeping in mind space taken up by the notification bar, as well as the title bar - unless you theme it without a title bar). You would need a different image for every possible screen resolution, and as more devices (notably tablets) begin to release, you're going to have to continue to provide more images and customized code for each different image as they release. You can see why this is not an ideal situation.

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int screenWidth = metrics.widthPixels();
int screenHeight = metrics.heightPixels();

Then you can place that into an if-then-else block, and determine the resolution, and set the image accordingly. I don't recommend this.

When it comes to displays and resolutions, it is not possible to have your images resized to any aspect ratio without either squishing / stretching them, or using letterboxes. I know this doesn't really answer you question, but if you can't get reliable screen size information from the OS, then try picking images for the largest resolution and cropping them for the smaller resolutions. Just make sure there is nothing interesting around the borders.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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