Images in different types of screen

Asked

Viewed 145 times

1

Right now I have these layout s to support the different screen sizes

inserir a descrição da imagem aqui

When I test the app on 4-inch or 4.5-inch devices, both will use the layout activity_main.xml which corresponds to normal size but repair that on the 4 inch device some images or text are cut because they do not fit on the screen.

How can I fix this?

  • You have to take into account that devices of equal size can have different densities. In addition to different layouts for each dimension has to have images sized for each density.

  • @Exact extension, I entered the folders drawablewith the various types of density however I do not know which is the size that each image has in each folder. I have a picture of 60x70 +- and looks good on devices xhdpi but when I pass to hdpiis bad enough

1 answer

2


You must take into account that devices of equal size can have different screen densities.

The space occupied by an image, relative to the screen dimensions, is different in each density. The lower the density the greater the space occupied.
For the occupied space to be equal it is necessary to provide images sized for each one of them.

You should create in the folder \res new drawable folders, one for each density, in the form drawable-xxx, where xxxx is:

  • ldpi
  • mdpi
  • hdpi
  • xhdpi
  • xxhdpi

The image sizes, to be included in each of them, are calculated in relation to the image in the mdpi folder.
Use an image editor that allows you to resize them, Photoshop for example.

The factors to be used are:

  • ldpi => 0.75
  • mdpi => 1
  • hdpi => 1.5
  • xhdpi => 2
  • xxhdpi => 3

With the dimensions of the MDPI the other dimensions are calculated by multiplying this dimension by the respective factor:

dimensão-hdpi = dimensão-mdpi * 1.5

When the starting dimension does not correspond to mdpi, divide it by the factor corresponding to that density and multiply by the density factor for which you want to calculate the dimensions.

For example, if you have an image that "looks good" in xhdpi, dimensions for other densities are calculated as such:

dimensão-xxx = (dimensão-xhdpi / 2) * factor-xxx
  • In the case of a legal image in mdpi, for example, xhdpi must be twice as many pixels? I don’t think I understand very well.

  • 1

    @underson Yes, that’s right.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.