[英]Scrolling issue with CollapsingToolbarLayout and RecyclerView
I am in a situation where i have CollapsingToolbarLayout
and RecyclerView
and so far every thing works pretty fine now i have a requirement where i have to use PagerSnapHelper
with RecyclerView
我处于一种情况,我有
CollapsingToolbarLayout
和RecyclerView
,到目前为止一切都很好,现在我有一个要求,我必须将PagerSnapHelper
与RecyclerView
一起使用
val snapHelper: SnapHelper = PagerSnapHelper()
snapHelper.attachToRecyclerView(activityNewsBinding.newsRecyclerView)
Once i attach to RecyclerView
my scroll on the RecyclerView
is not smooth anymore only when i am collapsing the CollapsingToolbarLayout
.一旦我附加到
RecyclerView
,只有当我折叠CollapsingToolbarLayout
时,我在RecyclerView
上的滚动才不再平滑。 I didn't find any issue related to PagerSnapHelper
and CollapsingToolbarLayout
我没有发现任何与
PagerSnapHelper
和CollapsingToolbarLayout
相关的问题
Here is my xml
这是我的
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>
I was able to solve this issue by making changes in PagerSnapHelper
class.我能够通过在
PagerSnapHelper
class 中进行更改来解决此问题。
I am in a situation where i have CollapsingToolbarLayout
and RecyclerView
and so far every thing works pretty fine now i have a requirement where i have to use PagerSnapHelper
with RecyclerView
我的情况是,我有
CollapsingToolbarLayout
和RecyclerView
,到目前为止,一切都很好,现在我有一个要求,我必须将PagerSnapHelper
与RecyclerView
一起使用
val snapHelper: SnapHelper = PagerSnapHelper()
snapHelper.attachToRecyclerView(activityNewsBinding.newsRecyclerView)
Once i attach to RecyclerView
my scroll on the RecyclerView
is not smooth anymore only when i am collapsing the CollapsingToolbarLayout
.一旦我附加到
RecyclerView
我在RecyclerView
上的滚动不再平滑,只有当我折叠CollapsingToolbarLayout
时。 I didn't find any issue related to PagerSnapHelper
and CollapsingToolbarLayout
我没有发现任何与
PagerSnapHelper
和CollapsingToolbarLayout
相关的问题
Here is my xml
这是我的
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.