在阅读设计库中SnackBar的源代码时,我发现了这种XML布局:
<view xmlns:android="http://schemas.android.com/apk/res/android"
class="android.support.design.widget.Snackbar$SnackbarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
style="@style/Widget.Design.Snackbar" />
我从未见过只有一个<view/>
标签(小写V,所以不是View
类)的这种XML。
我的第一个猜测是它的工作原理类似于<fragment/>
标签,根据class
属性创建自定义视图,但为什么要使用这种符号表示法,而不直接编写:
<android.support.design.widget.Snackbar.SnackbarLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
style="@style/Widget.Design.Snackbar" />
非常感谢