开发者

Aliasing a layout resource with same name just different screen qualifier

I have a layout that is different for portrait and landscape; however on tablets (e.g. really big screen, xlarge layout qualifier) 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 was thinking of using an alias. But I c开发者_JAVA技巧an't figure out from the Android docs how to reference a qualifier specific layout in my statement...

Ideas?


I was fighting with exactly! same problem and finally found a solution, so even if question is quite old, maybe someone find it useful

  1. put portrait layout into /res/layout/abc.xml (you already have it)

  2. put landscape layout into /res/layout/abc_land.xml

  3. create file layout.xml with content

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

Important is, that your layout.xml file contain reference to improved (landscape) file abc_land.xml, that is stored also in layout directory and also files are under values-x directories, not layout-x once.

Also I tried to put into layout directory two files abc_land.xml and abc_port.xml and create on them alias from /res/values-land/, /res/values-port/ and also /res/values-xlarge/ directories, and seems to work, so it's also usable solution to make in layouts some "order"!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜