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?
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.
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