简体   繁体   English

带有CollapsingToolbarLayout的Android RecyclerView平滑滚动问题

[英]Android RecyclerView with CollapsingToolbarLayout smooth scroll issue

I want to use CollapsingToolbarLayout with RecyclerView , like Whatsapp . 我想用CollapsingToolbarLayoutRecyclerView ,像Whatsapp

Here is the captured video : https://sendvid.com/0oi2lxx5 这是捕获的视频: https : //sendvid.com/0oi2lxx5

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 . 我想使用RecyclerView平滑滚动它。

So here is my profile_activity.xml : 这是我的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>

I am using: 我在用:

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'

How can I fix this? 我怎样才能解决这个问题?

Well i will explain how to solve issue , now my layout is super smooth ; 好吧,我将解释如何解决问题,现在我的布局非常平滑;

Actually i dont know how its solved , but ; 实际上我不知道它是如何解决的,但是;

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

My activity_profile.xml like : 我的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>

And the content_profile_edit.xml like : 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>

I had problems with RecyclerView and CollapsingToolbarLayout as well (did not collapse at all). 我也遇到了RecyclerView和CollapsingToolbarLayout问题(根本没有崩溃)。 Try using the current version 23.4.+ of recyclerview, appcompat and design if you're not doing already. 如果尚未使用,请尝试使用当前版本的recyclerview,appcompat和design 23.4。+。

/**
google solve this issue in 26 api level .I spent my whole day finally I found this answer. For Demo You create  one android studio Scrolling Activity and do following changes upgrade all repository to 26 version and you will see this scrolling smoothly effect.
**/

apply plugin: 'com.android.application'

android {
    **compileSdkVersion 26
    buildToolsVersion "26.0.1"**
    defaultConfig {
        applicationId "com.example.sandeep.quantauser"
        minSdkVersion 19
        **targetSdkVersion 26**
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile files('libs/ksoap2-android-assembly-3.0.0-jar-with-dependencies.jar')
    compile files('libs/apache-jakarta-commons-net-1.4.1.jar')
    compile 'com.theartofdev.edmodo:android-image-cropper:2.4.+'
    compile 'com.github.bumptech.glide:glide:3.7.0'
    testCompile 'junit:junit:4.12'
    compile files('libs/itextpdf-5.4.0.jar')
    **compile "com.android.support:support-core-utils:26.0.2"
    compile 'com.android.support:design:26.0.2'
    compile 'com.android.support:appcompat-v7:26.0.2'
    compile 'com.android.support:cardview-v7:26.0.2'**
}

**allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}**

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 CollapsingToolbarLayout,Android ViewPager和EditText-&gt;平滑滚动(垂直滚动)问题 - CollapsingToolbarLayout, Android ViewPager and EditText -> Smooth Scrolling(vertical scroll) Issue 平滑滚动不适用于 Android RecyclerView 的初始滚动 - Smooth Scroll Not Working on Initial Scroll for Android RecyclerView CollapsingToolBarLayout和NestedScrollView平滑滚动问题 - CollapsingToolBarLayout and NestedScrollView smooth scroll issues CollapsingToolbarLayout 和 RecyclerView 的滚动问题 - Scrolling issue with CollapsingToolbarLayout and RecyclerView CollapsingToolbarLayout 在 RecyclerView 滚动时折叠不一致 - CollapsingToolbarLayout collapses inconsistently on RecyclerView scroll 如何在CollapsingToolbarLayout中滚动Recyclerview - How to scroll Recyclerview inside CollapsingToolbarLayout Android水平RecyclerView在垂直NestedScrollView中平滑滚动 - android horizontal recyclerview smooth scroll in vertical nestedscrollview 使用RecyclerView Android设计库实现平滑滚动 - Achieving smooth scroll with recyclerview android design library RecyclerView或CollapsingToolbarLayout中的WebView如何滚动? - WebView in RecyclerView or CollapsingToolbarLayout how to scroll? RecyclerView平滑滚动动画 - RecyclerView Smooth Scroll animation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM