我想在布局XML文件中输入一些注释,我该怎么做?
发布于 2010-08-15 03:07:12
正如其他人所说,XML中的注释是这样的
<!-- this is a comment -->
请注意,它们可以跨越多行
<!--
This is a comment
on multiple lines
-->
但它们不能嵌套
<!-- This <!-- is a comment --> This is not -->
此外,您不能在标记内使用它们
<EditText <!--This is not valid--> android:layout_width="fill_parent" />
发布于 2013-10-21 04:24:59
万维网联盟(W3C)实际上定义了一个评论接口。其定义是all the characters between the starting ' <!--' and ending '-->' form a part of comment content and no lexical check is done on the content of a comment
。
有关详细信息,请访问developer.android.com网站。
因此,您只需在任何开始和结束标记之间添加注释即可。在Eclipse IDE中,只需输入<!--
,就会自动为您完成注释。然后,您可以在两者之间添加注释文本。
例如:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context=".TicTacToe" >
<!-- This is a comment -->
</LinearLayout>
特别提到in between
的目的是因为您不能在标记中使用它。
例如:
<TextView
android:text="@string/game_title"
<!-- This is a comment -->
android:layout_height="wrap_content"
android:layout_width="fill_parent"/>
是错误的,并将给出以下错误
Element type "TextView" must be followed by either attribute specifications, ">" or "/>".
发布于 2010-08-15 02:46:46
XML注释以<!--
开头,以-->
结尾。
例如:
<!-- This is a comment. -->
https://stackoverflow.com/questions/3484643
复制相似问题