是的,我查了一下!
<!-- comment -->
似乎是正确的选择,
但我在android-studio中收到错误
Gradle:解析XML时出错:格式不正确(无效令牌)
当我这样做的时候
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<!-- android:background="?android:attr/selectableItemBackground" -->
android:id="@+id/imageButton"
android:layout_alignParentTop="true"
android:src="@drawable/gfx_select_medium"
android:layout_marginRight="22dp"/>
任何帮助表示赞赏,谢谢!
XML注释不能放在标记标记内。移动评论例如在您的上方或下方 ImageButton
标签。
这是 规范 参考,重点补充:
评论可能出现在文档的任何位置 外 其他 标记
哪里 标记 定义为:
标记采用开始标记,结束标记,空元素标记,实体引用,字符引用,注释,CDATA部分分隔符,文档类型声明,处理指令,XML声明,文本声明以及任何处于的空白区域的形式。文档实体的顶级(即文档元素之外,而不是任何其他标记内)
它不仅仅是AS。您需要将注释放在结束标记之外 </>
做一些类似的事情
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton"
android:layout_alignParentTop="true"
android:src="@drawable/gfx_select_medium"
android:layout_marginRight="22dp"/>
<!-- android:background="?android:attr/selectableItemBackground" -->
看到 这个链接 和 这个 从W3关于xml评论。简而言之,它说
[定义:注释可能出现在其他标记之外的文档中的任何位置;
注意
在其他标记之外
从第一个链接和
[定义:Markup采用开始标签,结束标签,...的形式
从第二个链接
您应该知道xml文件中的注释被认为是XmlComment类型的节点,因此如果您加载xml文件,那些节点将被加载,您可以在解析加载的内容时避免它们或过滤它们。
所以,这将是正确的格式,
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton"
android:layout_alignParentTop="true"
android:src="@drawable/gfx_select_medium"
android:layout_marginRight="22dp"/>
<!-- android:background="?android:attr/selectableItemBackground" -->
或者你可以看到这个 链接..