android XML 文件注释

android的XML文件注释一般采用 <!--注释内容 -->的方式进行,但是有时候却不能进行注释,如
[html]  view plain copy
  1. <Button  
  2.     android:id="@+id/button2"  
  3.     android:layout_width="fill_parent"  
  4.        <!-- 控件高度 -->  
  5.     android:layout_height="wrap_content"  
  6.     android:layout_weight="1"  
  7.     android:text="LinearLayout和RelativeLayout互助使用" />  
  8. 释会使得注释后面的代码不能运行,这是为什么呢?在网上没有找到说明,通过翻阅书籍,终于知道原因了  

在XML中,形如    <Button           />      的表示方式,其中“/>”的含义表示这个XML中没有内文,他是一个最小组成单元,也就是说他的中间不能包含其他任何< >的代码,所以在<Button />中间注释会出现错误

对比整个XML文件,我们为什么可以在其中间注释呢,看代码

[html]  view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout android:id="@+id/right"  
  3.     xmlns:android="http://schemas.android.com/apk/res/android"  
  4.     android:layout_width="fill_parent"  
  5.     android:layout_height="fill_parent">  
  6.   
  7.     <!-- 在这里注释是没有问题的 -->  
  8.     <TextView android:id="@+id/right_view1"  
  9.         android:background="@drawable/yellow" android:layout_width="fill_parent"  
  10.         android:layout_height="wrap_content" android:text="第二组第一项" />  
  11.     <!-- 在这里注释也是没有问题的 -->  
  12.     <TextView android:id="@+id/right_view2"  
  13.         android:background="@drawable/blue"  
  14.         android:layout_width="fill_parent"  
  15.         android:layout_height="wrap_content"  
  16.         android:layout_below="@id/right_view1" android:text="第二组第二项" />  
  17. </RelativeLayout>  

注意看到,在注释的前面有一个“>”符号,这就是我们能够在他中间进行注释的原因,他的完整结构是

<RelativeLayout ></RelativeLayout>

这就不是最小组成单元的表示方式了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值