我将SwipeRefershLayout
与可能崩溃的AppBarLayout
一起使用。但是,如果用户向上滚动布局并向下滚动,则SwipeRefreshLayout
启用刷新模式,尽管布局未在顶部滚动。我修复了这个错误:
appBar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, final int verticalOffset) {
refreshLayout.setEnabled(verticalOffset == 0);
}
});
它完美无缺!但我现在注意到用户在进行向上滑动时可以隐藏SwipeProgressBar
。 (当SwipeRefreshLayout
显示此SwipeProgressBar
时,启用刷新模式)。
如何解决?
我的xml:
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="250dp"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsingToolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginBottom="32dp"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/parallax"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/orange"
android:minHeight="250dp"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:clipToPadding="false"
android:paddingBottom="28dp">
<!-- my header -->
</RelativeLayout>
</FrameLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax"
app:popupTheme="@style/AppTheme.PopupOverlay"/>
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="bottom"
android:background="@color/primary"
app:tabGravity="fill"
app:tabMode="scrollable"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>