android studio xml文件如何添加注释

即只能在组件布局代码后,或者在组件的前面添加注释。

#注释格式:
Android的XML文件注释一般采用 <!--注释内容 -->的方式进行

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

例如:

<?xml version="1.0" encoding="utf-8"?>

<!-- 在这里注释是没有问题的 -->  
<TextView android:id="@+id/right_view1"  
    android:background="@drawable/yellow" android:layout_width="fill_parent"  
    android:layout_height="wrap_content" android:text="第二组第一项" />  
<!-- 在这里注释也是没有问题的 -->  
<TextView android:id="@+id/right_view2"  
    android:background="@drawable/blue"  
    android:layout_width="fill_parent"  
    android:layout_height="wrap_content"  
    android:layout_below="@id/right_view1" android:text="第二组第二项" />  

猜你喜欢

转载自blog.csdn.net/weixin_44025103/article/details/89226516