首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Android布局xml中的注释

Android布局xml中的注释
EN

Stack Overflow用户
提问于 2010-08-15 02:44:12
回答 6查看 186.4K关注 0票数 161

我想在布局XML文件中输入一些注释,我该怎么做?

EN

回答 6

Stack Overflow用户

发布于 2010-08-15 03:07:12

正如其他人所说,XML中的注释是这样的

代码语言:javascript
复制
<!-- this is a comment -->

请注意,它们可以跨越多行

代码语言:javascript
复制
<!--
    This is a comment
    on multiple lines
-->

但它们不能嵌套

代码语言:javascript
复制
<!-- This <!-- is a comment --> This is not -->

此外,您不能在标记内使用它们

代码语言:javascript
复制
<EditText <!--This is not valid--> android:layout_width="fill_parent" />
票数 267
EN

Stack Overflow用户

发布于 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中,只需输入<!--,就会自动为您完成注释。然后,您可以在两者之间添加注释文本。

例如:

代码语言:javascript
复制
<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的目的是因为您不能在标记中使用它。

例如:

代码语言:javascript
复制
<TextView 
    android:text="@string/game_title"
    <!-- This is a comment -->
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"/>

是错误的,并将给出以下错误

代码语言:javascript
复制
 Element type "TextView" must be followed by either attribute specifications, ">" or "/>".
票数 42
EN

Stack Overflow用户

发布于 2010-08-15 02:46:46

XML注释以<!--开头,以-->结尾。

例如:

代码语言:javascript
复制
<!-- This is a comment. -->
票数 19
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3484643

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档