Android 标记视图,它是一个<;包括>;布局

Android 标记视图,它是一个<;包括>;布局,android,android-layout,android-xml,Android,Android Layout,Android Xml,我声明一个布局并使用它重用另一个xml布局。我需要标记布局,以便以编程方式引用它 <include layout="@layout/cell" android:layout_height="48dp" android:layout_width="match_parent" android:tag="0" /> 当我使用findViewByTag(“0”)

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

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


当我使用findViewByTag(“0”)时,返回null。如果我用布局/单元格的内容替换包含的布局,它会工作,这使我认为“tag”属性不适用于包含的布局。有人能证实或否认这一点吗?

正如文件所说

     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.

标签仅用于携带您在其上指定的信息,而不标识版面本身

Nice find on docs,但实际上您可以。Android SDK中包括View.findViewByTag()@Patrick我猜标签不会与数字一起使用。。试着用字母代替。android:tag=“id1”。。并更新我..它需要一个字符串,在本例中为“0”。在我用@Patrick替换一个可重用的布局之前,这个带有标记的布局就已经工作了,因为我认为标记在include和merge中不起作用。但您仍然可以使用@+id来查找包含视图。