0

I am building an app and I have about 20 Fragments that have XML layout files with Constraint Layout. Now I would like to create layout files for both phones and tablets. So I would like to have 3 version of each XML layout file:

  1. One XML layout file of each Fragment for Smartphones
  2. One XML layout file of each Fragment for Tablets with 8' display size and 1280 x 800 display resolution
  3. One XML layout file of each Frament for Tablets with 8' display and 1980 x 1200 display resolution

My question is how can I do that? I have to create the XML layout files for each of my Fragments but where shall I save them such that Android know which layout file to choose? I found some other question on Stackoverflow like this Android layout folders for different screen sizes or Drawable folder for 8 inch tablets. But here they only distinguish the layouts by the dp number. But when having 2 tablets with the same display size (in my case 8') and different resolution, the dp number should be different. How can I take this into account.

Reminder: Can't anybody say something about how to create layouts for different screen sizes and resolutions?

VanessaF
  • 515
  • 11
  • 36
  • "The Android system helps you achieve density independence by providing density-independent pixels (dp or dip) as a unit of measurement that you should use instead of pixels (px)." https://developer.android.com/guide/practices/screens_support.html In other words, you should give that approach a try even if both 8 inch tablets have different resolutions. Their system is designed with that kind of problem in mind. – Stephan Branczyk Sep 01 '22 at 20:40
  • @StephanBranczyk: Thanks Stephan for your answer. Generally I don't use dp because I would like to make the layout scalable for different screen sizes and when using dp you can't do that because the sizes will not scale – VanessaF Sep 01 '22 at 20:42
  • Have you been using dp for the font sizes as well? Because you're supposed to use sp for the fonts, not dp. And I'm curious, what have you been using instead of dp? – Stephan Branczyk Sep 01 '22 at 20:44
  • Actually I don't use dp and sp at all because then you don't have a layout for different screen sizes. I use sdp and ssp from this library https://github.com/intuit/sdp. Thus, the sizes and fonts scale with the layout size as opposed to dp – VanessaF Sep 01 '22 at 20:46
  • I noticed that for a tablet it is advisable to make another layout file. So maybe to have 2 layout files for each Fragment. One for smartphones and one for tablets. And in both I would use sdp and ssp to have them scale. But I don't know where and how to store the 2 different layout files such that Android will choose the right one depending on the device use (tablet or smartphone). Any idea how to do this? – VanessaF Sep 01 '22 at 20:49
  • They were using dp for their textSize, which is goes against the Android design guidelines, no wonder they had to create a library to fix this issue. https://github.com/intuit/sdp/blob/master/sdp-android/src/main/res/layout/dp_example.xml – Stephan Branczyk Sep 01 '22 at 20:51
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/247742/discussion-between-vanessaf-and-stephan-branczyk). – VanessaF Sep 01 '22 at 20:52

0 Answers0