PeterMmm
PeterMmm

Reputation: 24630

Why all attributes are prefixed?

What is the design advantage to do this

<TextView
    android:layout_width="105px"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />

and not this

<android:TextView
    layout_width="105px"
    layout_height="wrap_content"
    text="@string/hello"
    />

Is that android: prefix everywhere not a little bit to chatty?

Upvotes: 3

Views: 212

Answers (5)

Michael Kay
Michael Kay

Reputation: 163262

I think the answer is: there is no advantage in this design. Which is why I've never seen anyone use it.

Upvotes: 0

Ludovic Kuty
Ludovic Kuty

Reputation: 4954

android is a namespace prefix and it is used to tell that those attributes are in the XML namespace bound to that prefix. You should have a namespace declaration somewhere in your XML document which looks like xmlns:android = "the namespace URI here". It is quite unusual to prefix attributes but it is necessary when attributes of a given XML vocabulary are found in XML elements not belonging to that vocabulary because it avoids collisions.

Upvotes: 1

Egor
Egor

Reputation: 40193

Have never seen the second variant in use and don't really know if it works or not. If yes - I'm sure you can use it if you want.

Upvotes: 0

Matthew Wilson
Matthew Wilson

Reputation: 3929

In XML, attributes have to be prefixed in order to be in a namespace; they don't automatically pick up the namespace of the element.

Upvotes: 1

Warpzit
Warpzit

Reputation: 28152

Its xml references afaik, look at the top view and see the link.

Upvotes: 0

Related Questions