How does IPR Layouts and Redimensions work?

2

Android there are so called " DPI ", which are densities per pixel . Each screen has its type of DPI such as:

  

Smartphones:

     
  • layout [?]
  •   
  • layout-ldpi [240x320 & 240x400]
  •   
  • layout-mdpi [320x480 & 480x854]
  •   
  • layout-hdpi [480x800 & 480x854]
  •   
  • layout-xhdpi [720x1280]
  •   
  • layout-xxhdpi [1080x1920]
  •   
  • layout-xxxhdpi [?]
  •   

Tablets:

     
  • layout-mdpi [600x1024 & 800x1280]
  •   
  • layout-xhdpi [2560x1800 | 2560x1600 | 2048x1536 & 1200x1920]
  •   
  • layout-tvhdpi [800x1280]
  •   

For each type of screen there are " folders " with different image sizes :

  
  • drawable
  •   
  • drawable-hdpi
  •   
  • drawable-large
  •   
  • drawable-ldpi
  •   
  • drawable-mdpi
  •   
  • drawable-xhdpi
  •   
  • drawable-xxhdpi
  •   
  • drawable-xxxhdpi
  •   

My doubts are as follows:

  
    

1) In each layout folder, I create files with the same .xml name     to the screen. But how do I know that android is using the screen     in that particular DPI? Is it some code that I have to insert for     does he use the layouts?

         

2) What is the "layout" and "drawable" folder named "pure" without using layout-ldpi for example? In this same question, what are the image sizes in the "pure drawable" and "pure layout" folders?

         

3) Assuming I have to create a background, landscape, and portrait at 800x600 resolution. The portrait is 800x600 and of course the landscape is 600x800. Should I create the background in these two resolutions? And how are these images properly called by Android?

         

4) Following the reasoning of the (3) question, for each resolution type, how do I know what size in px is ideal for images, icons, "normal" images and others?

         

5) If I want to create specific layouts as examples for the "sw600dp" dpi type. What should I do?

         

6) Following the reasoning of the (5) issue, you really need to create these types of custom layouts, or just the dpi I mentioned above already stick ?

         

7) How does creating layouts for tablets work? And how do I "layer" layouts of tablets with those of "smartphones" within the same Android project?

         

8) There are also folders of type "values", "values-v21", "values-v22". What is the purpose of these folders and what should be inserted into each of them?

  

I thank you for your patience, and please kindly follow the order of the questions so that there is no confusion.

    
asked by anonymous 31.05.2017 / 15:35

1 answer

2

1) Android knows the resolution of the device and automatically chooses the folder (if created) that has the closest resolution in DPI of the resolution detected. If there is no folder with the resolution defined in the name, it will take the normal folder even in the case of layouts, the "layout" folder.

2) As for the pure name, it means that it is the default folder, ie Android will query this folder only if there are no corresponding folders with qualifiers that apply, such as the "layout-ldpi" you mentioned , if the phone is LDPI and this folder exists, it will use its files first, otherwise it will use the pure folder. If you are not creating images for different resolutions (and saving in their folders), save the image at the highest resolution possible.

3) By the same logic as the answers above. You create a "drawable-land" folder and save the landscape images with the same name as the equivalent portrait images that are simply "drawable". At runtime Android will get the image of the right folder because it will know in which orientation the device will be and will use the same principle of the above answer, try to match the current scenario that the app meets the folder name which would best suit the scenario.

4) You have to define what size in DP's the image will occupy in the layout, then convert this value to pixels when it will generate the final images for each resolution (XXHDPI, LDPI, etc). Do a quick search on Google, have several websites that show the calculation formula or even convert and generate images for the various resolutions in DP that the app will work.

5) Same logic as usual, create a "layout-sw600dp" folder and create an XML with the same name as the file that will run at the default resolution, which is in the "layout" folder.

6) Creating custom layouts for multiple resolutions will always provide a better user experience as you control how your app will appear on multiple screen sizes. Here are some good practices on this site: link

7) Answered at 5, but depending on the difference of components between a mobile and tablet layout for the same Activity, you will need to address this in the Activity code.

8) The "values" folder serves to define and organize data that has a great chance of being reused in various parts of the app, so it will be easier to maintain them because they are isolated from the code, eg Strings no strings.xml), Themes for Views (they are in styles.xml), dimensions (they stay in dimension.xml) and so on. These numeric quantifiers are to specify that the folder should be used for a particular version of the API or above and can be used in any other resource folder besides the values such as layout, drawable, etc. For example, if you want a given integer value to be X in API's 21 (Lollipop) or higher, put it in the "values-v21" folder, otherwise the value that is in the "pure" value folder will be used. The same goes for a layout, for example, if you want to use some component that just runs from Nougat, then you would create a layout in "layout-v23".

Here are good explanations of all this:

link link

I also recommend taking a look at this course. By chance I did this week (it's very short) and answers all your questions.

link

This one is great too:

link

Both are official Google courses.

    
31.05.2017 / 20:17