为什么样式和布局不使用android命名空间?

Mac*_*rse 15 xml android

例如,在创建时:

<TextView
    style="@style/blah"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello" />

<include
    layout="@layout/footer"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"/>
Run Code Online (Sandbox Code Playgroud)

可能的原因: stylelayout在编译时得到处理,但我不是100%肯定.

编辑:

用同样的事情packageAndroidManifest.xml的文件.

bot*_*aap 4

查看 的来源LayoutInflater,似乎没有明显的原因说明为什么它layout位于 include 标签中而不是android:layout。我想由于 include 标签是布局中的特殊情况,因此不需要 android 前缀。

然而,包含标签在编译时不会被处理,否则它现在就不会出现了,LayoutInflater不是吗;)

至于style,我不确定,但我认为原因是命名空间属性是在构造函数中定义XML和传递的。然而,样式不是在该集合中传递的,而是作为单独的参数传递的。所以我认为原因是这是一个始终存在的参数,而命名空间前缀属性是动态的并且是.AttributeSetViewstyleView

所以我没有给出明确的答案,但也许有帮助;)