我遇到了應用程序中摺疊工具欄佈局的預期滾動行爲問題。爲了確保我知道我在做什麼,我創建了一個簡單的測試項目,並能夠達到預期的結果,但在該示例中使用了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