1.CoordinatorLayout的出现。
继上一篇https://blog.csdn.net/m0_37667770/article/details/79606434博客,对于这些个性化的设计我想民间这么通用,谷歌工程师也会照猫画虎去设计来提供开发者提供更好的方法把。果不其然,CoordinatorLayout就有很好的解决了这个也算是麻烦的设计。CoordinatorLayout如果你查看了google提供的api那么就会知道CoordinatorLayout的重要性了。自己去看看谷歌介绍,如下:http://android.xsoftlab.net/reference/android/support/design/widget/CoordinatorLayout.html
As a container for a specific interaction with one or more child views
By specifying Behaviors for child views of a CoordinatorLayout you can provide many different interactions within a single parent and those views can also interact with one another. View classes can specify a default behavior when used as a child of a CoordinatorLayout using the DefaultBehavior annotation.
Behaviors may be used to implement a variety of interactions and additional layout modifications ranging from sliding drawers and panels to swipe-dismissable elements and buttons that stick to other elements as they move and animate.
Children of a CoordinatorLayout may have an anchor. This view id must correspond to an arbitrary descendant of the CoordinatorLayout, but it may not be the anchored child itself or a descendant of the anchored child. This can be used to place floating views relative to other arbitrary content panes.
作为一个协调一个或多个子控件的容器控件。它会带给你跟多的帮助。
2.属性Behavior:
上面也说了可以通过CoordinatorLayout的属性Behavior来和其他子控件进行各种交互。可以去API中仔细看看Behavior的作用:可以和子控件进行交互,滑动,拖拽,闪动等。
A Behavior implements one or more interactions that a user can take on a child view. These interactions may include drags, swipes, flings, or any other gestures.
3.看看效果如下:
4.上代码来实现我们FloatingActionButton和Toobar的隐藏和显示
上一篇总我们通过滑动RecylclerView监听滑动的dy来通过接口设置属性动画解决的可以让Toobar和下面的FloatingActionButton上滑消失下滑显示。今天我们通过CoordinatorLayout来进行解决达到这个效果。
第一CoordinatorLayout作为协调容器控件,对于自己所包含的控件可以协调进行子控件之间的交互,这里监听滑动控件RecyclerView的滑动通过Behavior反馈到FloatingActionButton。它为我们提供了继承类 CoordinatorLayout.Behavior而且他有子类的…自己可以查看哦!这里不多说了。它提供了layout_behavior属性进行关联子空间和滑动控件进行交互。代码如下:
1.在布局文件中
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.ls.lsn16_materialdesign_fab_animation_behavior.MainActivity">
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_list"
android:paddingTop="42dp"
android:clipToPadding="false"
android:clipChildren="false"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<android.support.v7.widget.Toolbar