Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why I can't define android attributes in default namespace?

Typically I have to write layout code like this:

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

I want to do something like this:

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

But this code doesn't run properly. Why?

And second question: Why element namen are in CamelCase and attributes are in under_score?

like image 807
Poma Avatar asked Jun 08 '11 16:06

Poma


1 Answers

XML default namespaces do not apply to attribute names. Hence, you always have to specify the namespace of an attribute, if it has one:

Default namespace declarations do not apply directly to attribute names; the interpretation of unprefixed attributes is determined by the element on which they appear.

So the real question is: Why did the Android designers define the element names without a namespace, putting only the attributes into the Android namespace?

As the document suggests, if the element names were in the Android namespace, then attribute names really wouldn't need their own namespace.

like image 178
Dan Breslau Avatar answered Sep 27 '22 21:09

Dan Breslau