The namespace doesn't reference nothing. It's necessary to know which attributes to pull.
Here is a snippet of the Android Source Code for a ViewGroup
.
<declare-styleable name="ViewGroup_Layout">
<!-- Specifies the basic width of the view. This is a required attribute
for any view inside of a containing layout manager. Its value may
be a dimension (such as "12dip") for a constant width or one of
the special constants. -->
<attr name="layout_width" format="dimension">
<!-- The view should be as big as its parent (minus padding).
This constant is deprecated starting from API Level 8 and
is replaced by {@code match_parent}. -->
<enum name="fill_parent" value="-1" />
<!-- The view should be as big as its parent (minus padding).
Introduced in API Level 8. -->
<enum name="match_parent" value="-1" />
<!-- The view should be only big enough to enclose its content (plus padding). -->
<enum name="wrap_content" value="-2" />
</attr>
<!-- Specifies the basic height of the view. This is a required attribute
for any view inside of a containing layout manager. Its value may
be a dimension (such as "12dip") for a constant height or one of
the special constants. -->
<attr name="layout_height" format="dimension">
<!-- The view should be as big as its parent (minus padding).
This constant is deprecated starting from API Level 8 and
is replaced by {@code match_parent}. -->
<enum name="fill_parent" value="-1" />
<!-- The view should be as big as its parent (minus padding).
Introduced in API Level 8. -->
<enum name="match_parent" value="-1" />
<!-- The view should be only big enough to enclose its content (plus padding). -->
<enum name="wrap_content" value="-2" />
</attr>
</declare-styleable>
https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/res/res/values/attrs.xml#3005
how does android knows what attributes are there for each elements
No different than defining custom attributes for your custom View
class, it pulls from a res/values/attrs.xml
that is located within the SDK.
Referencing a section there.
Once you define the custom attributes, you can use them in layout XML files just like built-in attributes. The only difference is that your custom attributes belong to a different namespace. Instead of belonging to the http://schemas.android.com/apk/res/android
namespace, they belong to http://schemas.android.com/apk/res/[your package name]
So, android
is just the namespace for the built-in attributes.