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...
?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.
Specifically, Android considers XML-based layouts to be resources, and as such, layout files are stored in the reslayout directory inside your Android project. Each XML file contains a tree of elements specifying a layout of widgets and containers that make up one View.
Using Android's XML vocabulary, you can quickly design UI layouts and the screen elements they contain, in the same way you create web pages in HTML — with a series of nested elements. Each layout file must contain exactly one root element, which must be a View or ViewGroup object.
What is contained within the Layout xml file? Orientations and layouts that specify what the display looks like.
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With