【发布时间】:2021-07-27 03:52:42
【问题描述】:
如果我创建了LinearLayout,添加xmlns:android="http://schemas.android.com/apk/res/android" 并关闭它,我是否需要再次将命名空间添加到同一文件中的另一个ViewGroup?
【问题讨论】:
标签: android xml android-linearlayout
如果我创建了LinearLayout,添加xmlns:android="http://schemas.android.com/apk/res/android" 并关闭它,我是否需要再次将命名空间添加到同一文件中的另一个ViewGroup?
【问题讨论】:
标签: android xml android-linearlayout
是的,如果您想使用 andorid: 前缀属性,则需要在每个 root 视图上声明命名空间。但是不,您不需要在同一文件中的不同 ViewGroup 上声明命名空间(并且不允许有多个根)。
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android">
<FrameLayout />
</FrameLayout>
您可以查看来自 W3Schools 的 this article,它描述了命名空间是什么以及它们为何如此重要。
【讨论】:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" [other views]> </LinearLayout> <LinearLayout [other views]> </LinearLayout> 这段代码可以吗,还是我需要这样做?:<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" [other views]> </LinearLayout> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" [other views]> </LinearLayout>