Why this line xmlns:android=“http://schemas.androi

2019-01-04 05:22发布

Why is this line needed in xml layout file?

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

11条回答
相关推荐>>
2楼-- · 2019-01-04 05:58

xmlns refers to the XML namespace

When using prefixes in XML, a so-called namespace for the prefix must be defined. The namespace is defined by the xmlns attribute in the start tag of an element. The namespace declaration has the following syntax. xmlns:prefix="URI".

Note: The namespace URI is not used by the parser to look up information.

The purpose is to give the namespace a unique name. However, often companies use the namespace as a pointer to a web page containing namespace information.

查看更多
我只想做你的唯一
3楼-- · 2019-01-04 06:03

xmlns:android Defines the Android namespace. This attribute should always be set to "http://schemas.android.com/apk/res/android".

refer http://developer.android.com/guide/topics/manifest/manifest-element.html

查看更多
该账号已被封号
4楼-- · 2019-01-04 06:04

I think it makes clear with the namespace, as we can create our own attributes and if the user specified attribute is the same as the Android one it avoid the conflict of the namespace.

查看更多
混吃等死
5楼-- · 2019-01-04 06:04

It is a XML name space declaration in order to specify that the attributes that are within the view group that it's decelerated in are android related.

查看更多
Fickle 薄情
6楼-- · 2019-01-04 06:06

To understand why xmlns:android=“http://schemas.android.com/apk/res/android” must be the first in the layout xml file We shall understand the components using an example

Sample::

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/container" >    
</FrameLayout>

Uniform Resource Indicator(URI):

  • In computing, a uniform resource identifier (URI) is a string of characters used to identify a name of a resource.
  • Such identification enables interaction with representations of the resource over a network, typically the World Wide Web, using specific protocols.

Ex:http://schemas.android.com/apk/res/android:id is the URI here


XML Namespace:

  • XML namespaces are used for providing uniquely named elements and attributes in an XML document. xmlns:android describes the android namespace.
  • Its used like this because this is a design choice by google to handle the errors at compile time.
  • Also suppose we write our own textview widget with different features compared to android textview, android namespace helps to distinguish between our custom textview widget and android textview widget
查看更多
我命由我不由天
7楼-- · 2019-01-04 06:08

In XML, element names are defined by the developer. This often results in a conflict when trying to mix XML documents from different XML applications. A user or an XML application will not know how to handle these differences. Name conflicts in XML can easily be avoided using a name prefix. When using prefixes in XML, a namespace for the prefix must be defined.The namespace can be defined by an xmlns attribute in the start tag of an element.The namespace declaration has the following syntax. xmlns:prefix="URI".

查看更多
登录 后发表回答