What is the purpose of layout.xml?

无人久伴 提交于 2019-12-05 00:11:37

问题


Why do people use layout.xmls in their resources like:

<resources>
    <item name="main" type="layout">@layout/main_twopanes</item>
</resources>

while there are folders for alternative resources to use particular XML for particular configuration?


回答1:


this is called Layout Aliases link here:

To avoid this duplication of the same file for tablets and TVs (and the maintenance headache resulting from it), you can use alias files. For example, you can define the following layouts:

And add these two files:

res/values-large/layout.xml:

<resources>
    <item name="main" type="layout">@layout/main_twopanes</item>
</resources>

res/values-sw600dp/layout.xml:

<resources>
    <item name="main" type="layout">@layout/main_twopanes</item>
</resources>

These latter two files have identical content, but they don’t actually define the layout. They merely set up main to be an alias to main_twopanes. Since these files have large and sw600dp selectors, they are applied to tablets and TVs regardless of Android version (pre-3.2 tablets and TVs match large, and post-3.2 will match sw600dp).



来源:https://stackoverflow.com/questions/11395551/what-is-the-purpose-of-layout-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!