Skip to content

Fix choppy AppBar collapsing with RecyclerView #103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

PhpXp
Copy link

@PhpXp PhpXp commented May 7, 2016

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.

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.
This time with better indentation.
@henrytao-me
Copy link
Owner

Sweet. Let me check.

@henrytao-me
Copy link
Owner

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.

@PhpXp
Copy link
Author

PhpXp commented May 9, 2016

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>

@henrytao-me
Copy link
Owner

Thanks @PhpXp

I will check it when I am back home.

@henrytao-me
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants