为什么人们在他们的资源
中使用layout.xml
,例如:
<resources>
<item name="main" type="layout">@layout/main_twopanes</item>
</resources>
虽然有用于替代资源的文件夹以将特定 XML 用于特定配置?
最佳答案
这称为布局别名
link here:
为避免平板电脑和电视出现相同文件的重复(以及由此导致的维护麻烦),您可以使用别名文件。例如,您可以定义以下布局:
并添加这两个文件:
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>
后两个文件具有相同的内容,但实际上并没有定义布局。他们只是将 main 设置为 main_twopanes 的别名。由于这些文件具有 large 和 sw600dp 选择器,因此无论 Android 版本如何,它们都适用于平板电脑和电视(3.2 之前的平板电脑和电视匹配 large,而 post-3.2 将匹配 sw600dp)。
关于android - layout.xml 的目的是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11395551/