写Android的时候想自己写个布局文件,索性就准备把自己生成的给全部注释掉,代码如下:
<!--
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</RelativeLayout>
-->
结果第一行就有一个让程序员恐惧的一个东西:红叉。。。。
如果把光标移动红叉上面就提示Premature end of file.
而且控制台会输出:Error in an XML file: aborting build.
上网百度了一下,发现没有找到我想要的答案,于是自己就开始乱捣鼓,结果还居然可以了,虽然不明觉厉
其实我只是简单地修改一下而已
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<!--
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
-->
</RelativeLayout>
对比了一下两者的区别,发现不同的是标签的包含范围,前者是<!-- -->中包含了全部,后者是<!-- -->包含了部分。
所以个人由此YY一个结论:<!-- -->的开始部分<!-- 不能放于文件的开头。
刚才再次测试了一下,发现如果<!-- -->的前面仅仅是<?xml version="1.0" encoding="utf-8"?>,那么也会报相同的错误。
有了这个YY, 验证起来也就简单多了,所以也算是解决了。
转载请注明原文地址,谢谢~