xmlns每一个xml文件里面都有,但是挺多玩家都不怎么关注。
首先xmlns是xml namespace的缩写,叫做xml命名空间.
在安卓xml中的使用是:xmlns:前缀(最常用android)=http://schemas.android.com/apk/res/应用程序包路径;
在xmlns定义后,所有带有相同前缀(比如android)的子元素都会与同一个xmlns相关联。避免xml解析器对xml解析时,发生名字冲突,这就是使用xmlns的必要性。
当然也可以使用自己定义的xmlns。例如
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:my="http://schemas.android.com/apk/res/demo.view.my"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<demo.view.my.MyView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
my:textColor="#FFFFFFFF"
my:textSize="22dp"
/>
</LinearLayout>
上面的代码段就自定义了my这个命名空间。对于my:属性名=值这一句话,就是在"http://schemas.android.com/apk/res/demo.view.my"这个文件的属性名赋予值。这样的话,就比较好理解了吧。
我们最常用的xmlns是xmlns:android="http://schemas.android.com/apk/res/android",如果没有这句话声明的话,我们就不能使用android:xxxxx的属性了。
具体参考文章https://blog.csdn.net/chuchu521/article/details/8052855。
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
xml中主要是strings.xml中,会遇到xliff标签,这个标签是在资源文件中,有动态的字符串,有不确定的值在里面,就可以用这个xliff:g的标签,同时,需要在文件开头进行声明<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">。