刷新后以及加载更多内容后,RecyclerView会弯曲到底部

时间:2019-07-29 16:08:20

标签: android stickyrecycleview

我有片段具有CollapsingToolbarLayout和SwipeRefreshLayout,而Viewpager包含片段在NestedScrollView内部具有recycleview。

一切正常,我的回收站滚动工作也很好,但是在某些情况下,我打开另一个片段然后回到它,或者滑动viewpager并回到它之后,回收站停止滚动到底部,然后又滚动回来。 / p> 在这些情况下,我的回收弯腰了: 1-当我加载更多数据时,recycleview会弯曲到底部,它会上升到以前的数据。 2-当我通过SwipeRefreshLayout重新加载片段时。 3-当我关闭片段并重新打开它时。

片段代码:

enter code here <androidx.coordinatorlayout.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"
android:background="@color/entage_blue_3"
android:fitsSystemWindows="true">

   <com.google.android.material.appbar.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/entage_blue_3"
    android:fitsSystemWindows="true"
    app:layout_scrollFlags="scroll|enterAlways"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <com.google.android.material.appbar.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:contentScrim="@color/entage_blue_3"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">


    </com.google.android.material.appbar.CollapsingToolbarLayout>

    </com.google.android.material.appbar.AppBarLayout>

  <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
    android:id="@+id/swipeRefreshLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

     <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

     <androidx.viewpager.widget.ViewPager
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/viewpager"
            android:visibility="gone">

            </androidx.viewpager.widget.ViewPager>

          </LinearLayout>

         </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

        </androidx.coordinatorlayout.widget.CoordinatorLayout>

Viewpager的片段:

  <RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layoutDirection="rtl">

<androidx.core.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/nestedScrollView"
    android:fillViewport="true"
    android:fitsSystemWindows="true"
    android:layout_gravity="fill_vertical"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recyclerView_items"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

    </RelativeLayout>

</androidx.core.widget.NestedScrollView>

 </RelativeLayout>

0 个答案:

没有答案