Incorrect Android documentation about layout aliases?

前端 未结 1 616
误落风尘
误落风尘 2021-02-14 19:58

I\'d like to figure out how to reuse or \"alias\" layouts with the least boilerplate code.

It seems that the Android documentation about layout aliases is incorrect, a

相关标签:
1条回答
  • 2021-02-14 20:48

    The first technique works, you just have to put your <resources> file in the correct folder. It should be in the values folders not the layout folders as you might when reusing layouts via <include>.

    For instance, suppose you have a layout named editor.xml that lives in the layout folder. Suppose you want to use a specialized layout on small and normal screen sizes. If you didn't care about repeating yourself, you would just copy and paste this layout into the layout-small and layout-normal folders and name it editor.xml in each folder. So you'd have three files named editor.xml.

    If you don't want to repeat yourself, you would place the specialized layout in the main layout folder and name it, say, compact_editor.xml. Then you'd create a file named layout.xml in the values-small and values-normal folders. Each file would read:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <item name="editor" type="layout">@layout/compact_editor</item>
    </resources>
    

    I've filed a documentation issue about the other two problems.

    0 讨论(0)
提交回复
热议问题