为什么这条线的xmlns:安卓=" HTTP://schemas.android.com/apk/res/android"必须是第一个在布局XML文件?第一个、这条、布局、

2023-09-12 22:08:38 作者:欠时间一个自圆其说ァ

为什么这条线是需要在XML布局文件?

Why this line is needed in xml layout file ?

任何人都可以给我一个解释?

Can anybody give me an explanation?

我试图理解,但没有成功,所以我在这里张贴了这个问题。

I tried to understand, but not succeeded, so I post this question here.

推荐答案

在XML,XMLNS声明了一个命名空间。事实上,当你做的:

In XML, xmlns declares a Namespace. In fact, when you do:

<LinearLayout android:id>
</LinearLayout>

而不是调用的android:ID ,XML将使用http://schemas.android.com/apk/res/android:id是唯一的。一般来说这个页面不存在(这是一个URI,而不是URL),但有时它是解释所使用的命名空间的URL。

Instead of calling android:id, the xml will use http://schemas.android.com/apk/res/android:id to be unique. Generally this page doesn't exist (it's a URI, not a URL), but sometimes it is a URL that explains the used namespace.

该命名空间具有pretty的大致相同用途的Java应用程序包名称。

The namespace has pretty much the same uses as the package name in a Java application.

这里是一个解释。

统一资源标识符(URI)

Uniform Resource Identifier (URI)

一个统一资源标识符(URI)是字符的字符串,   标识互联网资源。

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

最常见的URI是统一资源定位符(URL),其   标识互联网域名地址。另一种,不那么常见的类型   URI是统一资源名称(URN)。

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).

在我们的例子中,我们将只使用网址。

In our examples we will only use URLs.