我遇到了应用程序中折叠工具栏布局的预期滚动行为问题。为了确保我知道我在做什么,我创建了一个简单的测试项目,并能够达到预期的结果,但在该示例中使用了NestedScrollView
,并且需要滚动的内容只是一个RelativeLayout
,其中包含CardView
以及大量文本。在真实应用程序的滚动内容是RecyclerView
,我认为这是问题。就好像RecyclerView正在处理滚动一样,并且父级CollapsingToolbar不在循环中。CollapsingToolbarLayout不会折叠
请注意,app:layout_behavior="@string/appbar_scrolling_view_behavior"
当前不在布局中。我曾尝试将它添加到各个地方,但没有获得理想的结果。
附加是一个应用程序的图像后,使用上面的折叠工具栏执行少量滚动而不会降低其高度。
<?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=".ui.ArticleListActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/toolbar_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/Theme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/theme_primary"
app:contentScrim="@color/theme_primary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:src="@drawable/empty_detail"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/app_name"
android:src="@drawable/logo" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/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/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.SwipeRefreshLayout>
</android.support.design.widget.CoordinatorLayout>
尝试添加应用程序:layout_behavior =“@字符串/ appbar_scrolling_view_behavior”以回收视图以及/ –
@AliHasanzade我试过了,但它导致RecyclerView移动到屏幕顶部。 – chris