本例是使用AppBarLayout来判断是否可以刷新的,其他的刷新请参考这个链接。...然后直接appbarlayout添加滑动监听,当verticalOffset=0的时候,即滑动到顶部,设置拦截点击事件,来实现刷新。 实现刷新和加载监听,此例只实现了刷新。
AppBarLayout是一个垂直的LinearLayout,实现了很多和协调布局一起合作的滚动属性。...AppBarLayout不能滚动,但是要有一个可以滚动的兄弟View。兄弟View需要设置AppBarLayout.ScrollingViewBehavior。...AppBarLayout是什么,效果是怎样的 使用AndroidStudio建立一个ScrollActivity,模板就是使用的AppBarLayout,不过例子里还使用了CollapsingToolbarLayout...scroll 修改AppBarLayout的子View的属性如下: AppBarLayout android:id="@+id...监听AppBarLayout滚动 可以通过设置监听器来监听AppBarLayout的移动,比如说随着滚动,更改AppBarLayout的透明度,代码如下: app_bar.addOnOffsetChangedListener
通常CoordinatorLayout、AppBarLayout、CollapsingToolbarLayout的搭配使用折叠的效果目前已经很常见了,在网上有很多的例子和文章,小编整理了一下知识点。...的OnOffsetChangedListener 的监听 appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener()...{ @Override public void onStateChanged(AppBarLayout appBarLayout, State state...appBarLayout, int i) { if (i == 0) { if (mCurrentState !...= State.IDLE; } } public abstract void onStateChanged(AppBarLayout appBarLayout, State
重写style属性 AppBarLayout android:id="@+id/app_bar" android
AppBarLayout一般用于赋予Toolbar(不限于Toolbar)滚动行为,AppBarLayout是一个垂直的LinearLayout,实现了Material Design中app bar的scrolling...AppBarLayout的子View应该声明想要具有的“滚动行为”,这可以通过layout_scrollFlags属性或是setScrollFlags()方法来指定。...AppBarLayout只有作为CoordinatorLayout的直接子View时才能正常工作,为了让AppBarLayout能够知道何时滚动其子View, 我们还应该在CoordinatorLayout...layout_height="match_parent" tools:context=".FloatingActivity"> AppBarLayout...app:title="标题"> AppBarLayout
通常AppBarLayout和CollapsingToolbarLayout是一起使用的,也就是CoordinatorLayout、AppBarLayout、CollapsingToolbarLayout...、Toolbar常常是组合应用的,AppBarLayout能够赋予Toolbar显示和消失的功能,而CollapsingToolbarLayout能够赋予Toolbar伸缩的功能 AppBarLayout...CollapsingToolbarLayout的使用方法也比较固定,AppBarLayout包裹CollapsingToolbarLayout,由于需要伸缩Toolbar,所以它使用的app:layout_scrollFlags...layout_height="match_parent" tools:context=".FloatingActivity"> AppBarLayout... AppBarLayout
零、前言: AppBarLayout+CoordinatorLayout:废话不多说,Material Design还是用图说话 1.scroll:首子控件吸顶:app:layout_scrollFlags...目测:需要2个及以上子控件才能吸顶 目测:RecyclerVieW加app:layout_behavior="@string/appbar_scrolling_view_behavior"可居AppBarLayout...layout_width="match_parent" android:layout_height="match_parent"> AppBarLayout...AppBarLayout首控件修改:app:layout_scrollFlags="scroll|exitUntilCollapsed"+minHeight 其他不变,其中minHeight决定保留高度...监听移动分度.gif mAlTitle.addOnOffsetChangedListener((appBarLayout, verticalOffset) -> { //下降分度 float
对于大家关心的额外功能,则主要有以下几点: 1、支持响应主体页面的滑动行为,即在主体页面上移或者下拉时,AppBarLayout能够捕捉到主体页面的滚动操作; 2、AppBarLayout捕捉到滚动操作之后...下面是AppBarLayout结合RecyclerView实现的工具栏向上滚动效果截图: ?...1、AppBarLayout的滚动依赖于主体视图的滚动,与主体视图相对应的,可将AppBarLayout称作头部视图。既然一个页面分为头部和主体两部分,那么就存在谁先滚谁后滚的问题了。...既然AppBarLayout的高度是变化的,那也得区分是滚一半还是滚全部。...同理,拉动AppBarLayout也有类似情况,当松开手指后,AppBarLayout得判断要不要继续向上收缩,或是继续向下展开。
AppBarLayout 虽然和 Toolbar 没有直接联系,但是当 Toolbar 内置在 AppbarLayout 中的时候,Toolbar 的效果增强了,这使得开发者非常愿意用 AppBarLayout...所以,基本上有 AppBarLayout 的地方就有 Toolbar。通过 AppBarLayout 实现一个可伸缩折叠的 Toolbar 也是本文的目的。...滑动大家应该很好理解,只有在 AppBarLayout 中的子 View 配置了 scroll 属性,这个 AppBarLayout 都会响应。 AppBarLayout appBarLayout, int verticalOffset) verticalOffset 是 AppBarLayout 相对于完全展开时没有滑动的距离...= (AppBarLayout) findViewById(R.id.app_bar); appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener
比如:在CoordinatorLayout中使用AppBarLayout,如果AppBarLayout的子View(如ToolBar、TabLayout)标记了app:layout_scrollFlags...android:layout_width="match_parent" android:layout_height="match_parent"> .support.design.widget.AppBarLayout...tabSelectedTextColor="#ff0000" app:tabTextColor="#ffffff" /> .support.design.widget.AppBarLayout...并且给这些组件设置如下属性来告诉CoordinatorLayout,该组件是带有滑动行为的组件,然后CoordinatorLayout在接受到滑动时会通知AppBarLayout 中可滑动的Toolbar
首先介绍下这里用到的控件:AppBarLayout+CollapsingToolbarLayout+Toolbar AppBarLayout + CollapsingToolbarLayout AppBarLayout...这里的Toolbar、imageView都是AppbarLayout的子控件。...也就是说,如果我们想要让我们的标题栏控件能够响应滑动事件的话,就需要用AppBarLayout作为他们的父容器。...也就是说,AppBarLayout只是提供给它的子控件们,按照从上到下的优先级来响应子控件设置的响应行为。...拿上面的例子说,CollapsingToolbarLayout是AppBarLayout的子控件,ImageView、Toolbar是AppBarLayout的孙子控件,如果你在ImageView、Toolbar
的距离 if (scrollHeight + appbarLayout.y < dy) { super.onNestedPreScroll(target...appbarLayout.addOnOffsetChangedListener { _, _ -> calculate() } recyclerView.addOnScrollListener(...()) bigTitle.alpha = 1 - smallTitle.alpha } 自动到顶部 如果 AppBarLayout 滑到一半手松开了,想自动收起来,让 RecyclerView...,都可以滑动 coordinatorLayout.canScroll(appbarLayout.y appbarLayout.y >= -barHeightDistance)...(0, (appbarLayout.y + barHeightDistance).toInt(), intArrayOf(0,0), intArrayOf(0,0), ViewCompat.TYPE_TOUCH
接着监听AppBarLayout的滚动,利用topMargin实现被“顶上去”的效果 拆分完毕,接下来就是实现了 实现 Tab的悬浮效果 利用CoordinatorLayout、AppBarLayout...具体的使用可以参考Android 详细分析AppBarLayout的五种ScrollFlags (CoordinatorLayout、AppBarLayout的详细用法我就不多说了) 然后,只要在...这时候只要在MainActivity中对AppBarLayout的滚动进行监听即可。...() { @Override public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset...Tips 问题:使用CoordinatorLayout时,滚动不流畅问题 解决方案:可以写个Behavior添加到AppBarLayout中。
如果你熟悉AppBarLayout和CollapsingToolbarLayout的话,也许可以很快做出类似以上的简单界面,具体地说,就是定义一个CoordinatorLayout嵌套AppBarLayout...之所以要嵌套这么多层,是因为要完成以下功能: 1、CoordinatorLayout嵌套AppBarLayout,这是为了让头部导航栏能够跟随内容视图下拉而展开,跟随内容视图上拉而收缩。...这个内容视图可以是RecyclerView,也可以是NestedScrollView; 2、AppBarLayout嵌套CollapsingToolbarLayout,这是为了定义导航栏下面需要展开和收缩的部分视图...渐变动画的思路有了,可谓万事俱备,只欠东风,再来一个导航栏的移动偏移监听器便行,正好有个现成的AppBarLayout.OnOffsetChangedListener,只需给AppBarLayout对象调用...(verticalOffset); int total = appBarLayout.getTotalScrollRange(); int alphaIn = offset; int alphaOut
="match_parent" tools:ignore="MissingDefaultResource"> AppBarLayout...android:id="@+id/appBarLayout" android:layout_width="match_parent" android:layout_height...="match_parent" tools:ignore="MissingDefaultResource"> AppBarLayout...android:id="@+id/appBarLayout" android:layout_width="match_parent" android:layout_height...="match_parent" tools:ignore="MissingDefaultResource"> AppBarLayout
然后,我们需要定义AppBarLayout与滚动视图之间的联系。...AppBarLayout.ScrollingViewBehavior描述了RecyclerView与AppBarLayout之间的依赖关系。...RecyclerView的任意滚动事件都将触发AppBarLayout或者AppBarLayout里面view的改变。...AppBarLayout里面定义的view只要设置了app:layout_scrollFlags属性,就可以在RecyclerView滚动事件发生的时候被触发: .support.design.widget.AppBarLayout...比如AppBarLayout.Behavior 就定义了这两个关键方法。这个behavior用于当滚动发生的时候让AppBarLayout发生改变。
然后,我们需要在 AppBarLayout 和 期望被滚动的 View 之间定义一个关联。...view 上发生滚动事件时通知 AppBarLayout。...在这种特殊情况下 AppBarLayout.ScrollingViewBehavior 描述了 RecyclerView 和 AppBarLayout 之间的依赖关系。...例如 AppBarLayout.Behavior 就定义了这两个关键方法。此 behavior 用来在滚动事件发生时触发 AppBarLayout 上的改变。...将 Google Map 嵌入 AppBarLayout 由于这个已被确认的 issue,目前在 AppBarLayout 中还不支持使用 Google Map。
appbar_scrolling_view_behavior"/> 2.string字符串: 再看一下这个string是什么鬼==>原来是一个安卓design包中内置的一个字符串 看起来很像一个类名有没有:AppBarLayout...android.support.design.widget.AppBarLayout...$ScrollingViewBehavior 3.对应类 果然有这个类:android.support.design.widget.AppBarLayout.ScrollingViewBehavior...debug.png 总得来说behavior就是: 在CoordinatorLayout中,让AppBarLayout里的首控件和添加behavior的控件进行联动,而实现酷炫逆天的效果, 其中child...为添加了behavior的那个控件,dependency为AppBarLayout。
layout_width="match_parent" android:layout_height="match_parent"> AppBarLayout... AppBarLayout...AppBarLayout做一个兼容。...如下添加代码: AppBarLayout android:layout_width="match_parent"...解决方法在AppBarLayout添加 android:fitsSystemWindows="true"
--AppBarLayout--> AppBarLayout>--> AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL:0) | (isSnap?...AppBarLayout.LayoutParams.SCROLL_FLAG_SNAP:0) | (isEnterAlways?...AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS:0) | (isEnterAlwaysCollapsed?
领取专属 10元无门槛券
手把手带您无忧上云