android - 为什么这一行 xmlns :android ="http://schemas.android.com/apk/res/android" must be the first in the layout xml file?

标签 android xml android-activity layout xml-namespaces

为什么xml布局文件需要这一行?

xmlns:android="http://schemas.android.com/apk/res/android" 

最佳答案

在 XML 中,xmlns 声明了一个命名空间。事实上,当你这样做时:

<LinearLayout android:id>
</LinearLayout>

xml 将使用 http://schemas.android.com/apk/res/android:id 而不是调用 android:id要独一无二。通常这个页面不存在(它是一个 URI,而不是一个 URL),但有时它是一个解释使用的命名空间的 URL。

命名空间的用途与 Java 应用程序中的包名几乎相同。

Here是一种解释。

Uniform Resource Identifier (URI)

A Uniform Resource Identifier (URI) is a string of characters which identifies an Internet Resource.

The most common URI is the Uniform Resource Locator (URL) which identifies an Internet domain address. Another, not so common type of URI is the Universal Resource Name (URN).

在我们的示例中,我们将只使用 URL。

关于android - 为什么这一行 xmlns :android ="http://schemas.android.com/apk/res/android" must be the first in the layout xml file?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7119359/

相关文章:

java - 在框架布局中显示 map fragment

Python Flask 应用程序无法解析 XML 请求数据

Android 小部件尺寸?

android 不同尺寸不工作

java - AlertDialog 中性按钮关闭对话框

javascript - 通过JS加载CSS

android - 实现 'com.github.hakobast:dropdown-textview:0.3.1'

android - 膨胀类 android.support.design.internal.BottomNavigationView 时出错

xml - GZIP Deflate 与 CURL(PHP) Web 服务问题

android - 如何从广播接收器向正在运行的 Activity 发送数据,