Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of layout.xml?

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?

like image 532
Eugene Avatar asked Jul 09 '12 13:07

Eugene


1 Answers

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).

like image 59
Padma Kumar Avatar answered Sep 29 '22 06:09

Padma Kumar