版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/dhl_1986/article/details/80262647
在上一篇文章中android Material Design 学习之四:FloatingActionButton 与 Snackbar 使用,点击FAB (悬浮按钮),弹出 Snackbar 会遮住FAB,为了解决这个问题,MD 提供了CoordinatorLayout 来很好的解决这个问题。
/**
* CoordinatorLayout is a super-powered {@link android.widget.FrameLayout FrameLayout}.
*
* <p>CoordinatorLayout is intended for two primary use cases:</p>
* <ol>
* <li>As a top-level application decor or chrome layout</li>
* <li>As a container for a specific interaction with one or more child views</li>
* </ol>
*/
从源码的解释来看,CoordinatorLayout 就是一个加强版的FrameLayout ,它有两种使用场景
1,作为顶级布局来使用
2,协调一个或者多个子View
也就是说CoordinatorLayout 可以监听其所有子控件的各种事件,然后做出最为合理的响应。
直接用CoordinatorLayout 替换FramLayout
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/tool_bar_layout"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:src="@mipmap/fab_add"
app:backgroundTint="@color/fab_ripple"
android:layout_gravity="bottom|right|end" />
</android.support.design.widget.CoordinatorLayout>
这样就不会再遮住FAB了。
当然了,这里Snackbar 第一个参数必须是CoordinateLayout 的子View 才会生效。
扫描二维码关注公众号,回复:
3531342 查看本文章