问题描述
我想实现折叠tollbar与刷卡刷新和recyclerview。当我试图滚动(当recyclerview只有一个项目)的工具栏崩溃,但是当我试图向下滚动到显示的工具栏,这是不可能的,因为刷下来的原因刷卡刷新。当recyclerview有更多的项目它完美的作品。
I'm trying to implement collapsing tollbar with swipe to refresh and recyclerview.When I'm trying to scroll (when recyclerview has only one item) toolbar collapse,but when I'm trying to scroll down to show toolbar, it's impossible because swipe down causes swipe to refresh. When recyclerview has more item it works perfectly.
有人能帮助我吗?
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="1dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="1dp"
android:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_scrollFlags="scroll|enterAlways" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/activity_main_swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.v7.widget.RecyclerView
android:id="@+id/cities_list"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</android.support.v4.widget.SwipeRefreshLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="16dp"
android:elevation="1dp"
android:onClick="addCity"
android:src="@drawable/ic_plus_white_36dp"
app:borderWidth="0dp" />
推荐答案
您可以设置onOffsetChanged监听器为您AppBarLayout和prevent刷卡清爽,直到AppBarLayout布局的偏移量为0。
You can set onOffsetChanged listener for your AppBarLayout and prevent to swipe refreshing until AppBarLayout layout offset 0.
这是很好的例子:https://gist.github.com/blackcj/001a90c7775765ad5212
这篇关于工具栏不显示与刷卡刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!