![](/img/trans.png)
[英]CoordinatorLayout in combination with CollapsingToolbarLayout, RecyclerView and Fragments issue
[英]Scrolling issue with CollapsingToolbarLayout and RecyclerView
我處於一種情況,我有CollapsingToolbarLayout
和RecyclerView
,到目前為止一切都很好,現在我有一個要求,我必須將PagerSnapHelper
與RecyclerView
一起使用
val snapHelper: SnapHelper = PagerSnapHelper()
snapHelper.attachToRecyclerView(activityNewsBinding.newsRecyclerView)
一旦我附加到RecyclerView
,只有當我折疊CollapsingToolbarLayout
時,我在RecyclerView
上的滾動才不再平滑。 我沒有發現任何與PagerSnapHelper
和CollapsingToolbarLayout
相關的問題
這是我的xml
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbarLayout"
android:layout_width="match_parent"
android:layout_height="500dp">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/expandedImage"
android:layout_width="match_parent"
android:layout_height="500dp"
android:scaleType="centerCrop"
android:src="@drawable/ic_launcher_background" />
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/newsRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="-30dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:context=".news.presentation.ui.MyNewsActivity" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
我能夠通過在PagerSnapHelper
class 中進行更改來解決此問題。
我的情況是,我有CollapsingToolbarLayout
和RecyclerView
,到目前為止,一切都很好,現在我有一個要求,我必須將PagerSnapHelper
與RecyclerView
一起使用
val snapHelper: SnapHelper = PagerSnapHelper()
snapHelper.attachToRecyclerView(activityNewsBinding.newsRecyclerView)
一旦我附加到RecyclerView
我在RecyclerView
上的滾動不再平滑,只有當我折疊CollapsingToolbarLayout
時。 我沒有發現任何與PagerSnapHelper
和CollapsingToolbarLayout
相關的問題
這是我的xml
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbarLayout"
android:layout_width="match_parent"
android:layout_height="500dp">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/expandedImage"
android:layout_width="match_parent"
android:layout_height="500dp"
android:scaleType="centerCrop"
android:src="@drawable/ic_launcher_background" />
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/newsRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="-30dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:context=".news.presentation.ui.MyNewsActivity" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.