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
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
. I didn't find any issue related to PagerSnapHelper
and CollapsingToolbarLayout
Here is my 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.
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
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
. I didn't find any issue related to PagerSnapHelper
and CollapsingToolbarLayout
Here is my 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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.