简体   繁体   English

CollapsingToolbarLayout 和 RecyclerView 的滚动问题

[英]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我处于一种情况,我有CollapsingToolbarLayoutRecyclerView ,到目前为止一切都很好,现在我有一个要求,我必须将PagerSnapHelperRecyclerView一起使用

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我没有发现任何与PagerSnapHelperCollapsingToolbarLayout相关的问题

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我的情况是,我有CollapsingToolbarLayoutRecyclerView ,到目前为止,一切都很好,现在我有一个要求,我必须将PagerSnapHelperRecyclerView一起使用

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我没有发现任何与PagerSnapHelperCollapsingToolbarLayout相关的问题

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM