Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why don't style and layout use the android namespace?

Tags:

android

xml

Example, when creating this:

<TextView
    style="@style/blah"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello" />

<include
    layout="@layout/footer"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"/>

Possible reason: style and layout get processed at compile time, but I am not 100% sure.

EDIT:

Same thing with package in the AndroidManifest.xml file.

like image 988
Macarse Avatar asked Mar 12 '12 20:03

Macarse


People also ask

What are namespaces in android?

Namespaces uniquely identify code/libraries. If I write an api that uses all the same names and such as the android api the only way to distinguish between my api and android api is to use the android namespace, or mine. i mean, this is the definition of what the namespace does, but it doesn't touch on the why.

What is namespace in android XML?

An XML Namespace has the properties: Namespace URI: Namespace name expressed as a URI to which the prefix is bound. prefix: syntactically, this is the part of the attribute name following the XMLConstants. XMLNS_ATTRIBUTE ("xmlns") in the Namespace declaration.

What is layout tag android?

The <layout> tag must be the root tag when you are using DataBinding . Doing so you are telling the compiler that you are using DataBinding and your layout will have special tags like <variable> or <import> , so you have to embed your layout within that tag.

What does tools ignore do?

UselessParent is an Android lint issue identifier for a check that tries to figure out whether a parent layout can be removed. tools:ignore="UselessParent" disables that check in the specified element and its children in case you want to suppress the lint message.


1 Answers

Looking at the source of LayoutInflater, there doesn't seem to be a obvious reason why it's layout in a include tag and not android:layout. I guess since the include tag is a special case in a layout there's no need for the android prefix.

The include tag is not processed at compile time however, else it wouldn't be in LayoutInflater now wouldn't it ;)

As for style, I don't know for sure, but I think the reason is that namespaced attributes are defined in XML and passed as AttributeSet in the View constructor. The style however isn't passed in that set, but as a separate parameter. So I think the reasoning is that style is a parameter that is always there, while namespace prefixed attributes are dynamic and custom for a View.

So no definite answer from me, but maybe it helps ;)

like image 183
botteaap Avatar answered Sep 27 '22 22:09

botteaap