http://blog.csdn.net/pipisorry/article/details/24833325

怎么在android的XML文件中添加注释

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

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

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

<RelativeLayout ></RelativeLayout>

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

  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. <TextView android:id="@+id/right_view1"
  8. android:background="@drawable/yellow" android:layout_width="fill_parent"
  9. android:layout_height="wrap_content" android:text="第二组第一项" />
  10. <!-- 在这里注释也是没有问题的 -->
  11. <TextView android:id="@+id/right_view2"
  12. android:background="@drawable/blue"
  13. android:layout_width="fill_parent"
  14. android:layout_height="wrap_content"
  15. android:layout_below="@id/right_view1" android:text="第二组第二项" />
  16. </RelativeLayout>

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

<RelativeLayout
        android:id="@+id/item_layout"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:orientation="vertical" >
        <!--  -->
        <LinearLayout
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:orientation="vertical" >
                  <!--  -->
        </LinearLayout>
</RelativeLayout>

皮皮blog

相关错误解决

Hardcoded string "???", should use @string resource

在布局文件中,文本的设置使用如下写法时会有警告:Hardcoded string "下一步", should use @string resourcecopy

  1. <Button
  2. android:id="@+id/button1"
  3. android:layout_width="118dp"
  4. android:layout_height="wrap_content"
  5. android:text="下一步" />"

虽然可以正常运行,但是这不是一个好习惯(如果你有个string="确定"在多个地方都用到,但是后来你想把它改为“确认”,你觉得是找到引用它的地方一个个改方便呢,还是直接在strings.xml里面改一处方便?你只看到了strings中增加了一条记录),应该在res/values/strings.xml中设置: copy

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <resources>
  3. <string name="message">下一步</string>
  4. </resources>

引用的时候使用

<span class="atn">android:text</span><span class="pun">=</span><span class="atv">"@string/message"</span>

就行了。这样做可以做到一改全改,在支持多语言时也是很有用的。另外,颜色的设置也最好在color.xm中类似设置。

from:http://blog.csdn.net/pipisorry/article/details/24833325

ref:

Android布局文件xml相关推荐

  1. Xamarin Android布局文件没有智能提示

    Xamarin Android布局文件没有智能提示 在Visual Studio 2015中,Android项目的Main.axml文件没有智能提示,不便于布局文件的编写.解决办法: (1)从Xama ...

  2. Android布局文件的布局方式

    Android布局文件的属性值解析说明:   1.android:id [为控件指定相应的ID] 2.android:text [指定控件当中显示的文字,需要注意的是,这里尽量使用strings.xm ...

  3. Android布局文件错误,android 布局文件常见错误

    1.'Missing contentDescription attribute on image' in XML 原因:缺少图片描述,在 ADT 16 开始会抛出这个警告,确保开发者为图片添加内容描述 ...

  4. Android布局文件之 include 详细介绍

    Android布局文件之 include 详细介绍 include简介 众所周知,include就是在一个布局中,导入另一个布局文件. 优势是:相同的页面只需写一次,提高了共通布局的复用性. 下面我们 ...

  5. [Android]Android布局文件中的android:id=@*属性使用方法汇总以及介绍

    由于项目需要进行Android开发,因此一边开发,一边查阅资料,一边总结了Android布局文件中android:id="@*"属性的使用方法汇总以及介绍.id资源的引用 andr ...

  6. Android 布局文件添加edittext报:The following classes could not be found错误

    一.问题描述 Android项目布局文件中,添加edittext后布局报以下错误: Exception raised during rendering: Java.lang.System.arrayc ...

  7. Android布局文件中的xmlns:tools作用以及用法

    最近被布局文件中的 xmlns:tools="http://schemas.android.com/tools" xmlns:lu="http://schemas.and ...

  8. android 布局文件中控件ID、name标签属性的命名包含“@”、“.”、“+”等等符号的含义...

    1.在项目的根目录有个配置文件"AndroidManifest.xml",是用来设置Activity的属性的如 <?xml version="1.0" e ...

  9. Android 布局文件Graphical Layout不显示预览

    在当前项目上右键Android Tools --->Fix Project Proerties--->再次右键当前项目:Close Project --->Open Project, ...

  10. Android布局文件怎样转java,android studio中从布局文件到mainactivity.java的控制流

    下面是一个android应用程序的代码片段,它生成一个随机数字表单1-20,用户猜中数字,当猜中数字后按下按钮时,将比较用户编写的数字(val)和应用程序生成的数字(rand_no). 比较之后,我希 ...

最新文章

  1. ELASTIC SEARCH 性能调优
  2. java ddd 领域事件_Cribbb基于DDD/Domain Event领域事件的开源PHP通知系统
  3. 盘点微信的前世今生,微信成功的必然和偶然
  4. Excel最强玩法!只用Excel就能做出「王者荣耀」战绩表
  5. 安装新版的winetricks_20170506-最新WineQQ8.9.1安装教程和常见问题解决方法
  6. 腾达ac5第三方固件_腾达AC9的刷固件指南
  7. 【转摘】图像思维与意识观念的统一——读毕建勋《子非鱼》有感(初稿)[1]
  8. Flutter Container设置 width 无效
  9. LabVIEW采集鼠标、键盘数据
  10. 【xla】三、【构图阶段】EncapsulateSubgraphsPass
  11. 忆暖行动|“ 还可以留一点做成柿饼,做法也很简单,就是挑硬柿子把皮削掉,用开水烫个几秒”
  12. Android7.1.1 remap鼠标右键为返回键
  13. 7-65 平面向量加法 (15分)
  14. vi ~/.bashrc如何保存退出
  15. MySQL密码策略管理插件validate_password
  16. h5打开手机扫码功能
  17. matlab中awgn给信号添加高斯白噪声
  18. gc2000导出丝印和坐标_【干货】GC2000(GC-PowerStation)软件导出贴片坐标视频教程
  19. 【金猿产品展】创宇蜜罐——网络威胁处置最便捷的蜜罐产品
  20. 计算机键盘打出来都是英语大写怎么办,电脑键盘切换大小写怎么变成CapsLock和Shift键...

热门文章

  1. java对获取的字节数组进行处理
  2. Android对话框
  3. Android开发中图表的使用
  4. ORACLE成果,天天10问(四)
  5. 39.django的ORM模型
  6. THUSC2016 游记
  7. 【穷举】用c#实现一个数组(1,1,2,2,3,3,4,4)排列,每两个相同数字中间都间隔了这个数字个数...
  8. ICLR 2022 论文列表公布,接收率高达 32%
  9. 博一结束后的一些反思 -- 该如何平衡科研与生活
  10. 【多模态】来自Facebook AI的多任务多模态的统一Transformer:向更通用的智能迈出了一步...