为什么这一行 xmlns:android="http://schemas.android.com/apk/res/android"必须是布局 xml 文件中的第一个? [英] Why this line xmlns:android="http://schemas.android.com/apk/res/android" must be the first in the layout xml file?

查看:32
本文介绍了为什么这一行 xmlns:android="http://schemas.android.com/apk/res/android"必须是布局 xml 文件中的第一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Why is this line needed in xml layout file?

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

推荐答案

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

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

<LinearLayout android:id>
</LinearLayout>

xml 将使用 http://schemas,而不是调用 android:id.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.

命名空间的用途与 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)标识 Internet 域地址.另一种不太常见的类型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).

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

In our examples we will only use URLs.

这篇关于为什么这一行 xmlns:android="http://schemas.android.com/apk/res/android"必须是布局 xml 文件中的第一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆