本文介绍了带有CollapsingToolbarLayout的Android RecyclerView平滑滚动问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想与Whatsapp一起使用CollapsingToolbarLayoutRecyclerView.

以下是捕获的视频: https://sendvid.com/0oi2lxx5

因此,当我向上滚动时可以,但是当我向下滚动时则不流畅.我想使用RecyclerView平滑滚动它.

So when I scroll up it's okay, but when I scroll down it's not smooth. I want to scroll it smoothly with RecyclerView.

这是我的profile_activity.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.design.widget.CoordinatorLayout
    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="match_parent"
    android:fitsSystemWindows="true">
    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:id="@+id/profile_recyclerview"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:layout_below="@+id/profileactivity_appbar" />

    <android.support.design.widget.AppBarLayout
        android:id="@+id/profileactivity_appbar"
        android:layout_width="match_parent"
        android:layout_height="400dp"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme3.AppBarOverlay">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/profileactivity_collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginStart="48dp"
            app:expandedTitleMarginEnd="64dp">

            <ImageView
                android:id="@+id/profileactivity_fullimage"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="centerCrop"
                android:fitsSystemWindows="true"
                app:layout_collapseMode="parallax"
                app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:layout_collapseMode="pin" />

        </android.support.design.widget.CollapsingToolbarLayout>

    </android.support.design.widget.AppBarLayout>




    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/fab_margin"
        app:layout_anchor="@id/profileactivity_appbar"
        app:layout_anchorGravity="bottom|right|end"
        app:backgroundTint="@color/ColorPrimary"
        android:src="@drawable/ic_create_white_48dp"/>

</android.support.design.widget.CoordinatorLayout>

我正在使用:

compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.android.support:recyclerview-v7:23.4.0'
compile 'com.android.support:design:23.4.0'

我该如何解决?

推荐答案

好,我将解释如何解决问题,现在我的布局非常平滑;

Well i will explain how to solve issue , now my layout is super smooth ;

  • 我删除了所有android:fitsSystemWindows="true"属性.
  • 然后将app:layout_scrollFlags="scroll|enterAlways"属性添加到CollapsingToolbarLayoutImageViewToolbar.
  • 并将所有元素移到xml中我的AppBarLayout之前.
    • i deleted all android:fitsSystemWindows="true" attributes.
    • then added app:layout_scrollFlags="scroll|enterAlways" attribute to CollapsingToolbarLayout , ImageView and Toolbar.
    • And moved all elements before my AppBarLayout in xml.
    • 我的activity_profile.xml喜欢:

      <?xml version="1.0" encoding="utf-8"?>
      <android.support.design.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/apk/res-auto"
          android:id="@+id/profileCoordinatorLayout"
          android:layout_width="match_parent"
          android:layout_height="match_parent">
      
      <ProgressBar android:indeterminate="true"
          android:layout_width="50dp" android:layout_height="50dp"
          android:id="@+id/profile_activity_progress"
          style="?android:attr/progressBarStyle"
          android:layout_gravity="center_vertical|center_horizontal"
          android:layout_centerVertical="true"
          android:layout_centerHorizontal="true"
          android:visibility="visible" />
      
      <ProgressBar android:indeterminate="true"
          android:layout_width="50dp" android:layout_height="50dp"
          android:id="@+id/profile_activity_progress_edit"
          style="?android:attr/progressBarStyle"
          android:layout_gravity="center_vertical|center_horizontal"
          android:visibility="gone" />
      
      
      <include layout="@layout/content_profile_edit"/>
      
      
      <android.support.v7.widget.RecyclerView
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:id="@+id/profile_recyclerview"
          app:layout_behavior="@string/appbar_scrolling_view_behavior" />
      
      <android.support.design.widget.FloatingActionButton
          android:id="@+id/fab"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:visibility="gone"
          android:layout_margin="@dimen/fab_margin"
          app:layout_anchor="@+id/profileactivity_appbar"
          app:layout_anchorGravity="bottom|right|end"
          app:backgroundTint="@color/ColorPrimary"
          android:src="@drawable/ic_create_white_48dp"/>
      
      <android.support.design.widget.AppBarLayout
          android:id="@+id/profileactivity_appbar"
          android:layout_width="match_parent"
          android:layout_height="400dp"
          android:visibility="gone"
          android:theme="@style/AppTheme3.AppBarOverlay">
      
          <android.support.design.widget.CollapsingToolbarLayout
              android:id="@+id/profileactivity_collapsing_toolbar"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              app:layout_scrollFlags="scroll|enterAlways"
              app:statusBarScrim="@color/ColorPrimaryDark"
              app:contentScrim="?attr/colorPrimary"
              app:expandedTitleMarginStart="48dp"
              app:expandedTitleMarginEnd="64dp">
      
              <ImageView
                  android:id="@+id/profileactivity_fullimage"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:scaleType="centerCrop"
                  app:layout_scrollFlags="scroll|enterAlways"
                  app:layout_collapseMode="parallax" />
      
              <android.support.v7.widget.Toolbar
                  android:id="@+id/toolbar"
                  android:layout_width="match_parent"
                  android:layout_height="?attr/actionBarSize"
                  app:layout_scrollFlags="scroll|enterAlways"
                  app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                  app:layout_collapseMode="pin" />
      
          </android.support.design.widget.CollapsingToolbarLayout>
      
        </android.support.design.widget.AppBarLayout>
      
      </android.support.design.widget.CoordinatorLayout>
      

      content_profile_edit.xml一样:

      <?xml version="1.0" encoding="utf-8"?>
      <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="match_parent"
          android:id="@+id/profile_edit_layout"
          android:layout_alignParentBottom="true"
          android:visibility="gone"
          app:layout_behavior="@string/appbar_scrolling_view_behavior">
      
      <android.support.v4.widget.NestedScrollView
          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:id="@+id/profile_fragment_nested"
          android:layout_height="match_parent"
          android:padding="10dp">
      
         <!-- other views -->
      
      </android.support.v4.widget.NestedScrollView>
      
      </RelativeLayout>
      

      这篇关于带有CollapsingToolbarLayout的Android RecyclerView平滑滚动问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 17:39