Reputation: 34530
Android layouts are defined in XML with this namespace declared in the root element:
xmlns:android="http://schemas.android.com/apk/res/android"
Example of an element:
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" />
android
prefix used instead of ommitting it like xmlns="http...
?Upvotes: 20
Views: 4683
Reputation: 7641
Interesting question! it sure feel a bit weird.
com.android.widget.TextView
(com.android.widget.*
can always be truncated). The java namespace of this class will be automagically resolved at compile time, so an xml namespace representing a fully qualified java namespace is not welcome here. But attributes can be mapped to any of the inherited java classes of the Element. Hence the namespace on attributes to allow inheritance.This is done like this mainly because the layout describes Java objects and Google here is using the XML namespace mechanism to help in mapping your Layout with Java objects. So there are collisions between the Java namespace world and XML namespace world. It also allow us developers to subclass elements, add our own attributes without worrying that the next version of the platform will maybe add an attribute with the same name.
See the two replies to this blog post by Dianne Hackborn, a well-known android engineer working at google: http://www.elharo.com/blog/software-development/xml/2008/09/16/android-xml-weirdness/
Upvotes: 8