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

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

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

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

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

<RelativeLayout ></RelativeLayout>

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

  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. <RelativeLayoutandroid: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. <TextViewandroid:id="@+id/right_view1"
  8. android:background="@drawable/yellow"android:layout_width="fill_parent"
  9. android:layout_height="wrap_content"android:text="第二组第一项"/>
  10. <!--在这里注释也是没有问题的-->
  11. <TextViewandroid: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. <?xmlversion="1.0"encoding="utf-8"?>
  2. <resources>
  3. <stringname="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:


更多相关文章

  1. Android(安卓)硬解码 MediaCodec 遇到的(部分手机绿屏)API21
  2. Android(安卓)-- service两种启动方式startService与bindService
  3. Android(安卓)适配之FileProvider的使用
  4. Android(安卓)Studio的NDK的两种编译方式ndk-build和CMake
  5. 【Android】使用SharedPreferences判断应用程序是否首次启动
  6. 实例详解Android文件存储数据方式
  7. android进行异步更新UI的四种方式(转载)
  8. Android解惑 - 为什么要用Fragment.setArguments(Bundle bundle)
  9. ffmpeg 怎么用

随机推荐

  1. Android使用webrtc实现检测用户是否在说
  2. apk安装 手机没sd卡安装失败解决方案
  3. Android(安卓)的HashMap介绍
  4. Android学习开发路线图
  5. Android 广播接收器注册与注销源码分析
  6. Android插件开发初探——分析篇
  7. Android Studio 单元测试
  8. android wifi 连接笔记
  9. Android学习笔记(38):Handler消息传递处
  10. Android在MediaMuxer和MediaCodec录制视