Fed*_*oca 248
正如其他人所说,XML中的注释就像这样
<!-- this is a comment -->
Run Code Online (Sandbox Code Playgroud)
请注意,它们可以跨越多行
<!--
This is a comment
on multiple lines
-->
Run Code Online (Sandbox Code Playgroud)
但它们不能嵌套
<!-- This <!-- is a comment --> This is not -->
Run Code Online (Sandbox Code Playgroud)
你也不能在标签内使用它们
<EditText <!--This is not valid--> android:layout_width="fill_parent" />
Run Code Online (Sandbox Code Playgroud)
Ani*_*kur 38
万维网联盟(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>
Run Code Online (Sandbox Code Playgroud)
特别提到的目的in between是因为你不能在标签内使用它.
例如:
<TextView
android:text="@string/game_title"
<!-- This is a comment -->
android:layout_height="wrap_content"
android:layout_width="fill_parent"/>
Run Code Online (Sandbox Code Playgroud)
是错误的,会出现以下错误
Element type "TextView" must be followed by either attribute specifications, ">" or "/>".
Run Code Online (Sandbox Code Playgroud)
Dan*_*yer 19
XML注释以<!--&结尾开头-->.
例如:
<!-- This is a comment. -->
Run Code Online (Sandbox Code Playgroud)
有两种方法可以做到这一点
开始您的评论,"<!--"然后结束您的评论"-->"
例 <!-- my comment goes here -->
突出显示要评论的部分,然后按CTRL + SHIFT + /
ctrl + shift + / 您可以注释代码。
<!--
<View
android:layout_marginTop="@dimen/d10dp"
android:id="@+id/view1"
android:layout_below="@+id/tv_change_password"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#c0c0c0"/>-->
Run Code Online (Sandbox Code Playgroud)
可以创建可用于注释/文档目的的自定义属性。
在下面的示例中,documentation:info定义了一个属性,带有示例注释值:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:documentation="documentation.mycompany.com"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/relLayoutID"
documentation:info="This is an example comment" >
<TextView
documentation:purpose="Instructions label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click here to begin."
android:id="@+id/tvMyLabel"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
documentation:info="Another example comment"
documentation:translation_notes="This control should use the fewest characters possible, as space is limited"
/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
请注意,在这种情况下,documentation.mycompany.com只是新自定义 XML 命名空间(of documentation)的定义,因此只是一个唯一的 URI 字符串- 只要它是唯一的,它就可以是任何东西。该documentation到右边xmlns:也可以是任何东西-这工作了以同样的方式android:XML命名空间定义和使用。
使用此格式,可以创建任何数量的属性,诸如documentation:info,documentation:translation_notes等,具有描述值一起,该格式是相同的任何XML属性。
总之:
xmls:my_new_namespace向 XML 布局文件中的根(顶级)XML 元素添加属性。将其值设置为唯一字符串<TextView my_new_namespace:my_new_doc_property="description" />