smooth-app-bar-layout icon indicating copy to clipboard operation
smooth-app-bar-layout copied to clipboard

Fix choppy AppBar collapsing with RecyclerView

Open PhpXp opened this issue 9 years ago • 5 comments

computeVerticalScrollOffset doesn't return accurate values - they can jump by 30px or more if all items don't have the same height. If possible, get the first ViewHolder and get it's top position and use it as the scroll offset.

PhpXp avatar May 07 '16 22:05 PhpXp

Sweet. Let me check.

henrytao-me avatar May 08 '16 23:05 henrytao-me

Hi @PhpXp

Can you describe what issue are you facing? What type of SmoothAppBarLayout are you using? Please send some code. The more detail you send the better I can give advice and troubleshoot.

If you check the code, you will see onScrollChanged method has a param called accuracy which indicates when the RecyclerView is actually hitting top or not. In most case, it's enough to handle.

henrytao-me avatar May 08 '16 23:05 henrytao-me

Oh right, here's a screen record: https://youtu.be/nH3ZspBldEw The jumping can be even more extreme when the heights of the items in the RecyclerView vary even more.

Here's someone on StackOverflow having a similar issue: http://stackoverflow.com/q/30361403/971972

And here's the code (don't mind the different package name, I downloaded the source to support minSdk 8):

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    android:id="@+id/swipe_layout"
    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/darkerBackground">

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/bus_list_refresh"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/prihodi_recyclerview"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clipToPadding="false"
            android:paddingBottom="4dp"
            android:paddingTop="172dp"
            tools:listitem="@layout/item_napoved"/>

    </android.support.v4.widget.SwipeRefreshLayout>

    <com.myapp.views.smooth.SmoothAppBarLayout
        android:layout_width="match_parent"
        android:layout_height="168dp">

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

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

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

    </com.myapp.views.smooth.SmoothAppBarLayout>

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

PhpXp avatar May 09 '16 06:05 PhpXp

Thanks @PhpXp

I will check it when I am back home.

henrytao-me avatar May 09 '16 07:05 henrytao-me

I am busy recently for the trip to Google I/O. I will have some free time this weekend. Let me think more about the issue and solution. I can't reproduce it on my side though.

henrytao-me avatar May 12 '16 14:05 henrytao-me