IT박스

왜이 줄 xmlns : android =“http://schemas.android.com/apk/res/android”가 레이아웃 xml 파일에서 첫 번째 여야합니까?

itboxs 2020. 6. 25. 22:01
반응형

왜이 줄 xmlns : android =“http://schemas.android.com/apk/res/android”가 레이아웃 xml 파일에서 첫 번째 여야합니까?


이 줄이 XML 레이아웃 파일에 필요한 이유는 무엇입니까?

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

XML에서 xmlns는 네임 스페이스를 선언합니다. 실제로, 할 때 :

<LinearLayout android:id>
</LinearLayout>

을 호출하는 대신 android:idxml은 http://schemas.android.com/apk/res/android:id 를 고유 하게 사용 합니다. 일반적으로이 페이지는 존재하지 않지만 (URL이 아닌 URI 임) 때때로 사용 된 네임 스페이스를 설명하는 URL입니다.

네임 스페이스는 Java 애플리케이션의 패키지 이름과 거의 동일한 용도로 사용됩니다.

여기 에 설명이 있습니다.

URI (Uniform Resource Identifier)

URI (Uniform Resource Identifier)는 인터넷 리소스를 식별하는 문자열입니다.

가장 일반적인 URI는 인터넷 도메인 주소를 식별하는 URL (Uniform Resource Locator)입니다. 그리 일반적이지 않은 또 다른 유형의 URI는 URI (Universal Resource Name)입니다.

이 예에서는 URL 만 사용합니다.


xmlns:android=“http://schemas.android.com/apk/res/android”레이아웃 xml 파일에서 첫 번째 여야 하는지 이해하려면 예제를 사용하여 구성 요소를 이해해야합니다.

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>

URI (Uniform Resource Indicator) :

  • 컴퓨팅에서 URI (Uniform Resource Identifier)는 리소스 이름을 식별하는 데 사용되는 문자열입니다.
  • 이러한 식별을 통해 특정 프로토콜을 사용하여 네트워크, 일반적으로 월드 와이드 웹을 통해 리소스 표현과 상호 작용할 수 있습니다.

예 : http://schemas.android.com/apk/res/android:id여기 URI입니다


XML 네임 스페이스 :

  • XML 네임 스페이스는 XML 문서에서 고유하게 명명 된 요소 및 속성을 제공하는 데 사용됩니다. xmlns:android안드로이드 네임 스페이스를 설명합니다.
  • 컴파일 타임에 오류를 처리하기 위해 Google에서 디자인 선택이기 때문에 이와 같이 사용됩니다.
  • 또한 textview안드로이드와 비교하여 다른 기능으로 자체 위젯을 작성한다고 가정하십시오 textview.Android 네임 스페이스는 사용자 정의 textview위젯과 안드로이드 textview위젯 을 구별하는 데 도움이됩니다

xmlns는 XML 네임 스페이스를 나타냅니다.

XML에서 접두사를 사용하는 경우 접두사에 대한 소위 네임 스페이스를 정의해야합니다. 네임 스페이스는 요소의 시작 태그에서 xmlns 속성으로 정의됩니다. 네임 스페이스 선언에는 다음과 같은 구문이 있습니다. xmlns : prefix = "URI".

참고 : 네임 스페이스 URI는 구문 분석기에서 정보를 찾는 데 사용되지 않습니다.

목적은 네임 스페이스에 고유 한 이름을 부여하는 것입니다. 그러나 종종 회사는 네임 스페이스 정보를 포함하는 웹 페이지에 대한 포인터로 네임 스페이스를 사용합니다.


xmlns : android Android 네임 스페이스를 정의합니다. 이 속성은 항상 "http://schemas.android.com/apk/res/android"로 설정해야합니다.

참조 http://developer.android.com/guide/topics/manifest/manifest-element.html를


이것은 XML 네임 스페이스 선언 일뿐입니다. 아래에 나열된 속성이 Android에 속하도록 지정하기 위해이 네임 스페이스를 사용합니다. 따라서 그들은 " android : "로 시작합니다 .

실제로 사용자 정의 속성을 작성할 수 있습니다. 따라서 두 속성의 이름이 동일하지만 다르게 동작하는 이름 충돌을 방지하기 위해 접두사 " android : "를 추가하여 이것이 Android 속성임을 나타냅니다.

따라서이 네임 스페이스 선언은 XML 파일 루트보기의 여는 태그에 포함되어야합니다.


  • Xmlns는 XML 네임 스페이스를 의미합니다.
  • XML에서 이름 충돌을 피하기 위해 작성되었습니다.
  • 다른 방법으로 이름 충돌을 피하려면 각 요소에 접두사를 제공해야합니다.
  • 각 xml 태그에서 접두사를 반복적으로 사용하지 않도록 xml의 루트에서 xmlns를 사용합니다. 따라서 xmlns : android =” http://schemas.android.com/apk/res/android 태그가 있습니다
  • 이제 안드로이드는 단순히 " http://schemas.android.com/apk/res/android " 네임 스페이스를 할당한다는 의미 입니다.
  • 이 네임 스페이스는 URL이 아니라 URI 대신 거의 사용되지 않는 URN (범용 리소스 이름)으로 알려진 URI입니다.
  • 이 안드로이드로 인해 XML 문서에서 android : xxxxxxx 등의 Android 관련 요소를 식별해야합니다.이 네임 스페이스가 없으면 android : xxxxxxx가 인식되지 않습니다.

평신도의 용어를 쓰려면 :

xmlns : android =” http://schemas.android.com/apk/res/android ”가없는 경우 Android 관련 태그는 레이아웃의 xml 문서에서 인식되지 않습니다.


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


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

This is form of xmlns:android ="@+/id". Now to refernce it we use for example

android:layout_width="wrap_content"
android:text="Hello World!"

Another xmlns is

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

which is in form of xmlns:app = "@+/id" and its use is given below

 app:layout_constraintBottom_toBottomOf="parent"
 app:layout_constraintLeft_toLeftOf="parent"

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.


xmlns:android This is start tag for define android namespace in Android. This is standerd convention define by android google developer. when you are using and layout default or custome, then must use this namespace.

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

From the <manifes> element documentation.


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

xmlns : is xml name space and the URL : "http://schemas.android.com/apk/res/android" is nothing but

XSD which is [XML schema definition] : which is used define rules for XML file .

Example :

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" 
android:layout_width="match_parent"
android:layout_height="match_parent">

<EditText
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:layout_marginBottom="4dp"
   android:hint="User Name"
  />
</LinearLayout> 

Let me explain What Kind of Rules ? .

  1. In above XML file we already define layout_width for our layout now IF you will define same attribute second time you will get an error .
  2. EditText is there but if you want add another EditText no problem .

Such Kind of Rules are define in XML XSD : "http://schemas.android.com/apk/res/android"

little bit late but I hope this helps you .


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.

참고URL : https://stackoverflow.com/questions/7119359/why-this-line-xmlnsandroid-http-schemas-android-com-apk-res-android-must-be

반응형