I would like to enter some comments into the layout XML files, how would I do that?
Syntax. A comment starts with <! -- and ends with -->. You can add textual notes as comments between the characters.
ctrl+shift+/ You can comment the code.
Allows notes and other human readable comments to be included within an XML file. XML Parsers should ignore XML comments. Some constrains govern where comments may be placed with an XML file.
This interface inherits from CharacterData and represents the content of a comment, i.e., all the characters between the starting ' <! -- ' and ending ' --> '. Note that this is the definition of a comment in XML, and, in practice, HTML, although some HTML tools may implement the full SGML comment structure.
As other said, the comment in XML are like this
<!-- this is a comment -->
Notice that they can span on multiple lines
<!--
This is a comment
on multiple lines
-->
But they cannot be nested
<!-- This <!-- is a comment --> This is not -->
Also you cannot use them inside tags
<EditText <!--This is not valid--> android:layout_width="fill_parent" />
The World Wide Web Consortium (W3C) actually defined a comment interface. The definition says 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
.
More details are available on developer.android.com site.
So you can simply add your comment in between any starting and ending tag. In Eclipse IDE simply typing <!--
would auto complete the comment for you. You can then add your comment text in between.
For example:
<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>
Purpose of specifically mentioning in between
is because you cannot use it inside a tag.
For example:
<TextView
android:text="@string/game_title"
<!-- This is a comment -->
android:layout_height="wrap_content"
android:layout_width="fill_parent"/>
is wrong and will give following error
Element type "TextView" must be followed by either attribute specifications, ">" or "/>".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With