Answers:
就像其他人说的那样,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" />万维网联盟(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 "/>".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"/>--><!-- comment here -->可以创建可用于注释/文档编制目的的自定义属性。
在下面的示例中,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>请注意,在这种情况下,documentation.mycompany.com仅仅是新的自定义XML名称空间(的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" />tools:名称空间,它确实会被丢弃。(发布此答案时可能不存在,但此页面继续吸引新观众。)
                    如果您想发表评论,Android Studio只需按:
Ctrl+ /在Windows / Linux上
Cmd/在Mac上为+ 。
这适用于XML文件(例如)和strings.xml代码文件(例如)MainActivity.java。
您还可以通过按Ctrl + Shift + /和Shift + /一行来添加注释。
令人难以置信的是,在2019年使用Android Studio 3.3(我不知道确切的版本,至少是3.3)的情况下,可以对XML使用双斜杠注释。
但是,如果在xml中使用双斜杠注释,IDE会显示警告。
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    // this works
    /* this works too */
    /*
    multi line comment
    multi line comment
    */
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World! yeah"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>Unexpected text found in layout file: ...。
                    从Federico Culloca的笔记中:
另外,您不能在标签内使用它们
手段; 您必须将注释放在文件的顶部或底部-您真正要添加注释的所有位置至少都在顶层布局标签内