Android 协调器布局
例子
这CoordinatorLayout是一个类似于FrameLayout但具有额外功能的容器,它FrameLayout在官方文档中被称为超级强大。
通过将a附加CoordinatorLayout.Behavior到CoordinatorLayout的直接子项,您将能够拦截触摸事件、窗口插入、测量、布局和嵌套滚动。
为了使用它,您首先必须在gradle文件中为支持库添加一个依赖项:
compile 'com.android.support:design:25.3.1'
可以在此处找到库的最新版本号
的一个实际用例CoordinatorLayout是使用FloatingActionButton.在这种特定情况下,我们将在其上创建一个RecyclerView带有aSwipeRefreshLayout和aFloatingActionButton的对象。您可以这样做:
注意FloatingActionButton是如何锚定到CoordinatorLayout的app:layout_anchor="@id/coord_layout"