I am a novice and now the moment came when I first encountered this problem, when on one screen the fonts and the distances between views look different from what you expect on different screens.

I googled, read offs and realized that everything depends on the density of the screen mainly. To solve this problem, create sub folders in the res folder for different densities.

and here are a few questions from the category of best practices that I want to clarify:

  1. There are 6 possible density options ldpi, mdpi, tvdpi, hdpi, xhdpi, xxhdpi , do you need to take into account all these densities and create 6 folders? Or is there something interchangeable so to speak ...
  2. If I create a subpack for layout files for each density, I also need to create the same sets of folders for images, so that each image has its own image ... True?
  3. Is it possible, instead of creating sets of folders for images, to work with vector images? I understand that it is possible, but someone still works with folders and someone with a vector ... It depends only on the developer (on the habit of how to work)?
  4. And the last question, if I allow 20 screens, it turns out you need to create 6 folders in each, lay down 20 layout files for each resolution. But how is this not to get confused when we assume you need to make a change to a file, you need to open 6 folders, find 6 corresponding files and change them in each one again? Right?
  5. Maybe some other tips that should be considered?
  • I advise you to examine the official documentation . There are answers to each of your questions. - Stas Lelyuk
  • A layout for one screen creates one, maximum two (phone / tablet) and uses a “rubber” layout (dimensions and distances are relative and are specified in units of density, and not absolute sizes in pixels). But the graphics are pre-scaled for density, or a vector (the official library appeared quite recently, so the vector is not very popular). There are already a lot of questions on the support of different screen resolutions on this resource and all the answers are there, use the search. - pavlofff
  • one
    look at this answer: stackoverflow.com/a/483756/177345 - pavlofff
  • Only that I read 2 of your answers on this topic, I think this is what you need! Thank! Now I will try - Aleksey Timoshchenko
  • @pavlofff and tell me another question so that the indents on the screens look the same you need to create a folder of diment, but see all the same every indent will have to be checked on all densities ... I have a look that there is no installation algorithm, right? - Aleksey Timoshchenko

1 answer 1

If you use dp for sizes and indents, and sp for font sizes, then from densities distances and dimensions will look the same on all densities. Distance and size problems begin when the application is used on devices with very different screen sizes in dp. Moreover, if the application is used only on phones, then as a rule it is enough to have only one layout and size. You just need to do it under the most popular resolution of phones - 360x640dp. And also take into account that the screen can shrink to 320x480dp for the most compact phones and crawl somewhere up to 480x720dp on all sorts of phablets. In general, design the markup so that it can be slightly compressed and stretched.

If you also need tablet support, then they usually require separate markup, and in some cases even two - for tablets with screens around 7 inches and for tablets of 9 inches or more. Moreover, if the arrangement of controls on the screen for tablets does not make sense, then you can do with one markup, but you can take out some sizes in dimensions and set them different values ​​depending on the screen sizes.

As a result, you will have a maximum of 3 folders with markup:

  • layout (for phones and general layouts)
  • layout-sw600dp (for tablets)
  • layout-sw720dp (for tablets with non-small screens ~ 9 "+)

Similar to folders with values: values, values-sw600dp and values-sw720dp. And folders for different densities will be needed only for images. I recommend to score on ldpi and tvdpi, since they almost never occur, well, and if anyone does, the system itself will correctly scale the image to the desired dpi. Thus, you need to cut images for the following densities: mdpi (1dp = 1px), hdpi (1dp = 1.5px), xhdpi (1dp = 2px), xxhdpi (1dp = 3px) and xxxhdpi (1dp = 4px).

  • As for tvdpi, I would not say ELSE yet, since there are of course very few television sets on an android, but there have never been any TV before - pavlofff
  • Yes, I know that if you use dp и sp then there should be no problems, but I created and tested the application on the Samsung S5, when I connected a Chinese phone to something (I don’t remember what it’s called), the picture was different, I won’t say that It didn’t look like that at all, but it was different ... What immediately catches your eye is that the fonts on the Chinese are clearly more ... on the Samsung 20 sp and on the Chinese 20 sp these are different sizes ... Therefore, I’m thinking of creating dimes folders Have you encountered such a problem? - Aleksey Timoshchenko
  • And this is also very useful advice about resolution. I tested it for Samsung C5 (1920 x 1080 (Full HD)), so I understand that this is not entirely correct following your advice ... You need to pick up a phone with 360x640dp, so that the picture looked predictable on most devices, right? - Aleksey Timoshchenko
  • sp is dp multiplied by the font size factor on the device, which can be set on the screen settings. Maybe you just have a normal text size on the S5, and an enlarged one on the Chinese. None of them will save you from this. You just need to either take into account that the user can set enlarged fonts and design a space for them with a margin, or use dp for fonts. On the S5, by the way, there is 360x640dp (xxhdpi). - xkor