一个XMLNS:机器人,如何实际工作? [英] A xmlns:android, how does that actually work?

查看:109
本文介绍了一个XMLNS:机器人,如何实际工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑在Android下得很好形成布局文件:

Consider the following perfectly well formed layout file on android:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Hello World, PurpleActivity"/>
</LinearLayout>

我看着这一点,并有好奇的ULR: http://schemas.android.com / APK / RES /安卓。所以,我试图进入到我的网页浏览器的地址栏也试图通过卷曲去取,但是这两种方法表明,它实际上并不存在。我找了一个类似于在Android的SDK文件夹中的APK / RES /安卓目录我的本地机器,但找遍止跌回升什么为好。所以,我想既然这个资源并不实际存在,也许我可以改变的xmlns:Android的行到任何我想要的。我继续和它更改为

I looked at this and got curious about that ULR: http://schemas.android.com/apk/res/android. So, I tried to enter it into my web browser's address bar and also tried to fetch it via CURL, but both methods showed that it doesn't actually exist. I looked for something akin to an apk/res/android directory in the android-sdk folder on my local machine, but that searched turned up nothing as well. So, I figured since this resource didn't actually exist, maybe that I could change the xmlns:android line to whatever I wanted. I went ahead and changed it to

http://schemas.android.com/apk/res/androidASDFASDFASDFASDFLKJSDFLEIE

,然后试图重新编译我的项目。我得到这个结果:

and then tried to recompile my project. I got this result:

-resource-src:
     [echo] Generating R.java / Manifest.java from the resources...
     [aapt]     (skipping hidden file '/Users/rutski/Desktop/purple/res/layout/.#main.xml')
     [aapt] /Users/rutski/Desktop/purple/res/layout/main.xml:2: error: No resource identifier found for attribute 'orientation' in package 'androidASDFASDFASDFASDFLKJSDFLEIE'
     [aapt] /Users/rutski/Desktop/purple/res/layout/main.xml:2: error: No resource identifier found for attribute 'layout_width' in package 'androidASDFASDFASDFASDFLKJSDFLEIE'
     [aapt] /Users/rutski/Desktop/purple/res/layout/main.xml:2: error: No resource identifier found for attribute 'layout_height' in package 'androidASDFASDFASDFASDFLKJSDFLEIE'
     [aapt] /Users/rutski/Desktop/purple/res/layout/main.xml:7: error: No resource identifier found for attribute 'layout_width' in package 'androidASDFASDFASDFASDFLKJSDFLEIE'
     [aapt] /Users/rutski/Desktop/purple/res/layout/main.xml:7: error: No resource identifier found for attribute 'layout_height' in package 'androidASDFASDFASDFASDFLKJSDFLEIE'
     [aapt] /Users/rutski/Desktop/purple/res/layout/main.xml:7: error: No resource identifier found for attribute 'text' in package 'androidASDFASDFASDFASDFLKJSDFLEIE'

这让我感到困惑。如果资源不反正存在,那么有什么关系,如果我改变的xmlns:Android的价值,其他一些不存在的资源?如果它确实存在,那么它在哪里?

This leaves me confused. If the resource doesn't exist anyway, then what does it matter if I change the xmlns:android value to some other nonexistent resource? And if it does exist, then where is it?

推荐答案

的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android声明XML命名空间preFIX。 的xmlns 表示这是关于一个命名空间声明。 机器人是preFIX。 http://schemas.android.com/apk/res/android 是一个URI - 一个字符串,它唯一标识该命名空间引用。 URI可以是抽象的东西(如在这种情况下);它不一定是在物理上位于东西的URL。

xmlns:android="http://schemas.android.com/apk/res/android" declares an XML namespace prefix. xmlns indicates it's about a namespace declaration. android is the prefix. http://schemas.android.com/apk/res/android is a URI - a string that uniquely identifies which namespace is referred to. The URI can be something abstract (as in this case); it is not necessarily a URL that physically locates something.

在一般情况下,你可以自由选择的实际preFIX。你可以极有可能取代机器人用别的东西,它仍然可以工作。

In general, you are free to choose the actual prefix. You can most likely replace android with something else and it will still work.

那么该属性的实际含义是我们需要从命名空间 http://schemas.android.com/apk/res/android 这里的节点工作,在这个文件中,我们将引用该命名空间为机器人

So what that attribute actually means is "We need to work with nodes from the namespace http://schemas.android.com/apk/res/android here, and in this file, we're going to refer to that namespace as android.

如果,在几个文件中,您可以定义使用相同的URI不同的命名空间prefixes,所有这些文件将涉及到同一个命名空间 - 因为URI是一样的。的preFIX可以看出氨基酸缩写符号用于参照实际的名称空间。的preFIX只能用来定义它的文件内。

If, in several files, you define different namespace prefixes using the same URI, all those files will be referring to the same namespace - because the URI is the same. The prefix can be seen a a shorthand notation for referring to the actual namespace. The prefix can only be used inside the file that defines it.

这篇关于一个XMLNS:机器人,如何实际工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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