When changing a build resource with the same name, just another screen qualifier

I have a layout that is different for portraiture and landscape; however, on tablets (for example, actually a large screen, xlarge layout specifier) ​​I want to use only the portrait version for both orientations.

/res/layout/abc.xml

/res/layout-land/abc.xml

/res/layout-xlarge/abc.xml

Since the first and last layouts are identical, I thought about using an alias. But I can not understand from Android docs how to refer to a specific specifier layout in my statement ...

Ideas?

+6
source share
1 answer

I fought for sure! the same problem and finally found a solution, so even if the question is quite old, maybe someone will find it useful

  • Put the portrait layout in /res/layout/abc.xml (you already have)

  • Place the terrain layout in /res/layout/abc_land.xml

  • create layout.xml file with content

     <?xml version="1.0" encoding="utf-8"?> <resources> <item name="abc" type="layout">@layout/abc_land</item> </resources> 
  • copy this file into your directories /res/values-land/ and /res/values-xlarge/

It is important that your layout.xml file contains a link to the improved (landscape) file abc_land.xml , which is also stored in the layout directory, and that the files are in the values-x directories, not layout-x once.

I also tried to put two files abc_land.xml and abc_port.xml in the layout directory and create an alias on them from /res/values-land/ , /res/values-port/ , as well as /res/values-xlarge/ directories and, seems to work, so this is also a useful solution to do some β€œorder” in the layouts!

+4
source

Source: https://habr.com/ru/post/893992/


All Articles