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

工具导航Map