简体   繁体   中英

Background images for different screens

In my application I have a background for activity. This is an image, I am going to use fitXY for it. I am ok if it will be resized a little (keeping aspect ration is not very important) but not very much. I am going to prepare few images with different size and for both Portrait and Landscape orientation. I am going to cover about 90% of devices. My question is the following:

  1. What images sizes I need for background?
  2. What folders under "res" I should put these images?

I would like to get very specific file sizes and folder name where to put these files. The solution should work on tablets as well.

I just used two images with maximum sizes (one portrait and one landscape). Then android resized the to smaller and it looks quite good for me.

  1. I have one background with resolution: 800*1200 px in drawable folder
  2. and another with resolution: 1200*800 px in drawable-land folder

This works pretty fine on tablets.

You have to create multiple resources for your app. Android has 4 resolutions (ldpi,mdpi,hdpi and xhdpi) and 4 generalized screen sizes (small, medium, large and extra large). So you have to make 4 layouts (or 3 if you don't plan on supporting tablets, since tablets come under the extra large category) to support the screen sizes.

Here's a general guide:

put layouts for small, medium, large and extra large in your res/ folder as follows:

res/layout/sample_layout.xml             // default layout
res/layout-small/sample_layout.xml       // layout for small screen size
res/layout-large/sample_layout.xml       // layout for large screen size
res/layout-xlarge/sample_layout.xml      // layout for extra large screen size

you can also use

res/layout-land/sample_layout.xml for landscape orientation for all screen sizes or you can target landscape layouts for specific screen sizes as res/layout-medium-land/sample_layout.xml

note that all the layouts have the same name.

once you have your layouts ready, you need to take care of image resolutions also

once again in your res/ folder add images like this:

res/drawable-ldpi/sample_image.png         // low density
res/drawable-mdpi/sample_image.png         // medium density
res/drawable-hdpi/sample_image.png         // high density
res/drawable-xhdpi/sample_image.png        // extra high density

once again, all the images have the same name.

general guidelines for designing images are:

ldpi is 0.75x dimensions of mdpi
hdpi is 1.5x dimensions of mdpi
xhdpi is 2x dimensinons of mdpi

generally, I design mdpi images for a 320x480 screen and then multiply the dimensions as per the above rules to get images for other resolutions.

Android will automatically select the best combination of layout and image depending on the device. For example, for a high resolution medium size device, layout-medium and high density image will be displayed to the user.

Make sure you create emulators for all these combinations and test your app thoroughly. here's the official docs for more info:

https://developer.android.com/guide/practices/screens_support.html

m/h/xh dpi are the most important . Combine that with the (most common) resolutions and you should be fine for your "90%" target.

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