【问题标题】:How to COMMENT in xml file ( in android studio layout file)? [duplicate]如何在 xml 文件中评论(在 android studio 布局文件中)? [复制]
【发布时间】:2017-04-17 12:23:21
【问题描述】:

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

【问题讨论】:

    标签: android xml android-studio


    【解决方案1】:

    <!-- your comment here -->

    这就像html评论

    【讨论】:

      【解决方案2】:

      例如

          <!--This is a comment-->
          <RelativeLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:padding="5dp">
      

      【讨论】:

        【解决方案3】:

        你可以像这样使用html comment tag

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

        但请注意,如果您在 android xml 标签中添加这样的注释:

        <LinearLayout
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           <!--WARNING This is not a valid comment. -->
        />
        

        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>
        

        【讨论】:

          猜你喜欢
          • 2018-03-11
          • 1970-01-01
          • 2022-08-04
          • 2014-12-07
          • 1970-01-01
          • 2016-05-11
          • 1970-01-01
          • 2015-11-25
          • 1970-01-01
          相关资源
          最近更新 更多