简体   繁体   English

Android布局中的xmlns属性

[英]xmlns attributes in Android layouts

I'm well-versed in Java, but not that familiar with XML. 我精通Java,但对XML并不熟悉。 In many of my layout/menu files, I have these lines: 在我的许多布局/菜单文件中,有以下几行:

xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"

Somtimes I have all of them, sometimes just some combination. 有时我拥有所有这些,有时只是某种组合。 Could somebody give an explanation towards these three lines? 有人可以对这三行作出解释吗? Under which scenarios should we include each one? 在哪种情况下我们应该包括每个场景? So far I have just been adding them in whenever Android Studio prompts me, but I would like to understand the use cases. 到目前为止,只要Android Studio提示我,我就一直将它们添加进来,但是我想了解用例。 Thanks! 谢谢!

Could somebody give an explanation towards these three lines? 有人可以对这三行作出解释吗?

Each declare a different XML namespace ( android , app , and tools , respectively). 每个声明一个不同的XML名称空间(分别为androidapptools )。

Under which scenarios should we include each one? 在哪种情况下我们应该包括每个场景?

If your XML file has one or more attributes prefixed with android: , you need to declare the android namespace. 如果您的XML文件具有一个或多个前缀为android:属性,则需要声明android名称空间。 Many XML files will have these, from framework-defined runtime attributes. 根据框架定义的运行时属性,许多XML文件将具有这些属性。

If your XML file has one or more attributes prefixed with app: , you need to declare the app namespace. 如果您的XML文件具有一个或多个前缀为app:属性,则需要声明app名称空间。 Some layout and menu resource files will have these, from library-defined attributes. 某些布局和菜单资源文件将具有库定义的属性中的这些文件。

If your XML file has one or more attributes prefixed with tools: , you need to declare the tools namespace. 如果您的XML文件具有一个或多个带有tools:前缀的属性,则需要声明tools名称空间。 Few resource files will have these, from attributes used to help the build tools understand what to do. 很少有资源文件具有这些属性,这些属性来自用于帮助构建工具理解该怎么做的属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM