【问题标题】:What is the difference between include tag and merge tag in android [duplicate]android中包含标签和合并标签有什么区别[重复]
【发布时间】:2016-04-18 11:28:08
【问题描述】:

我只需要有人告诉我是否正确理解了何时使用<include> 以及何时使用<merge>

所以,我制作了一个标题布局,我想将它包含在其他 XML 布局中:

这是我添加两个视图的合并示例

  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
           <TextView
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"        
        android:text="Header text" />
</LinearLayout>

我以这种方式将它包含到其他一些 XML 中(这是非常基本的):

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
               <include android:id="@+id/header" layout="@layout/top"
             android:layout_width="fill_parent" android:layout_height="wrap_content"
            />
</LinearLayout>

这会很好用,没有问题。但是为了优化代码,我必须在包含的布局中使用&lt;merge&gt;。所以顶部布局不应该有标签&lt;LinearLayout&gt;,但它必须看起来像这样:

<merge xmlns:android="http://schemas.android.com/apk/res/android">
     <TextView
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"        
            android:text="Header text" />
</merge>

我理解正确吗?

【问题讨论】:

标签: android xml layout merge include


【解决方案1】:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-13
    • 1970-01-01
    • 1970-01-01
    • 2015-01-25
    • 2021-12-22
    • 2019-09-23
    • 1970-01-01
    相关资源
    最近更新 更多