如何在xml文件中注释(在android studio布局文件中)?

dan*_*nte 1 xml android android-studio

我是编写 xml 文件的初学者,它与 C 和 C++ 不同。那么,任何人都可以告诉我如何在此文件中发表评论吗?

ישו*_*ותך 6

您可以像这样使用html 注释标签:

<!--This is a comment. -->
Run Code Online (Sandbox Code Playgroud)

但请注意,如果您在 android xml 标签中添加注释,如下所示:

<LinearLayout
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   <!--WARNING This is not a valid comment. -->
/>
Run Code Online (Sandbox Code Playgroud)

Android Studio 布局编辑器会给你一个错误。您只能将其添加到 xml标记之外,如下所示:

<LinearLayout
       android:layout_width="match_parent"
       android:layout_height="wrap_content">

       <!--This is a valid comment. -->

       <TextView
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
       />
    </LinearLayout>
Run Code Online (Sandbox Code Playgroud)