android 标签的使用

当我们用inclue标签复用layout的时候,会将复用layout的根视图导入进来,比如你的主layout main.xml是一个Linearlayout,然后你的复用layout reuse.xml的根视图也是Linearlayout,这样当你用include 标签将reuse.xml 导入到main.xml的时候,其实main.xml中就有两个嵌套的Linearlayout,其实这不是我们需要的。在这种情况下我们可以使用

merge标签作为reuse.xml的root view,如下


<merge xmlns:android="http://schemas.android.com/apk/res/android">

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/add"/>

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/delete"/>

</merge>
这样,当使用include导入的时候,main.xml中只有增加了两个button,而没有多余的Linearlayout

发布了16 篇原创文章 · 获赞 4 · 访问量 1万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章