标记视图是<include>布局</include>

时间:2014-06-12 17:19:04

标签: android android-layout android-xml

我声明了一个布局并使用了重用另一个xml布局。我需要标记布局,以便以编程方式引用它。

            <include layout="@layout/cell"
                 android:layout_height="48dp"
                 android:layout_width="match_parent"
                 android:tag="0" />

当我使用findViewByTag(&#34; 0&#34;)时返回null。如果我用布局/单元格的内容替换包含的布局,它会起作用,这使我认为&#39;标记&#39;属性不适用于包含的布局。任何人都可以确认或否认这个吗?

1 个答案:

答案 0 :(得分:0)

正如文件所述

     Tags

    Unlike IDs, tags are not used to identify views. Tags are essentially an extra piece of information
    that can be associated with a view. They are most often used as a convenience to store data related to 
   views in the views themselves rather than by putting them in a separate structure.

标记仅用于携带您在其上指定的信息,而不是识别布局本身