xmlns,就是xmls name space 的简称,

1: 为什么要有这个xmlns呢? 为了区别不同类的相同名字的属性,避免冲突,参考本文最下面的摘录的内容,或者这个链接


2: android 中的xmlns 有android, app,fresco,tools等

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:fresco="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.kodulf.viewpager.MainActivity">


2.1 首先是android,因为有了这个命名空间,我们才可以使用anroid:id,anroid:layout_width这些

2.2 app,这个是例如我们使用了v4包中的TabLayout了,这个时候TabLayout有它自己的一些属性,那么可以直接app:

<android.support.design.widget.TabLayout  
            android:id="@+id/tablayout_video"  
            android:layout_width="match_parent"  
            android:layout_height="@dimen/tablayout_height"  
            app:tabBackground="@drawable/tablayout_background"  
            app:tabIndicatorHeight="0dp"  
            app:tabSelectedTextColor="@color/white"  
            app:tabTextAppearance="@style/TabLayoutTextStyle"  
            app:tabTextColor="@color/white" />


2.3 还有fresco,这个是我们导入了第三方的fresco的包以后,如果想要使用fresco自定义的一些属性的时候,需要首先导入这个命名空间,然后才能使用

https://www.fresco-cn.org/docs/getting-started.html

在xml布局文件中, 加入命名空间:

<!-- 其他元素-->
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:fresco="http://schemas.android.com/apk/res-auto"
    android:layout_height="match_parent"
    android:layout_width="match_parent">
加入SimpleDraweeView:


<com.facebook.drawee.view.SimpleDraweeView
    android:id="@+id/my_image_view"
    android:layout_width="130dp"
    android:layout_height="130dp"
    fresco:placeholderImage="@drawable/my_drawable"
  />





2.4 然后是tools 这个:主要是xml 使用的时候的工具,具体的可以参考:http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0309/2567.html

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++




xmlns的介绍:链接



XML


命名冲突

XML

XML

<table>
</table>

XML

<table>
</table>

XML

XML


使用前缀来避免命名冲突

此文档带有某个表格中的信息:

<h:table>
</h:table>

XML

<f:table>
</f:table>

现在,命名冲突不存在了,这是由于两个文档都使用了不同的名称来命名它们的 <table> 元素 (<h:table> 和 <f:table>)。

通过使用前缀,我们创建了两种不同类型的 <table> 元素。


使用命名空间(Namespaces)

XML

xmlns:h="http://www.w3.org/TR/html4/"

XML

xmlns:f="http://www.w3school.com.cn/furniture"

xmlns


XML Namespace (xmlns) 属性

XML

xmlns:namespace-prefix="namespaceURI"

当命名空间被定义在元素的开始标签中时,所有带有相同前缀的子元素都会与同一个命名空间相关联。

注释:用于标示命名空间的地址不会被解析器用于查找信息。其惟一的作用是赋予命名空间一个惟一的名称。不过,很多公司常常会作为指针来使用命名空间指向实际存在的网页,这个网页包含关于命名空间的信息。

请访问 http://www.w3.org/TR/html4/