Skip to content
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

Scroll view sluggish and jittery #595

Open
1 task done
LeoXJ978 opened this issue Dec 7, 2021 · 0 comments
Open
1 task done

Scroll view sluggish and jittery #595

LeoXJ978 opened this issue Dec 7, 2021 · 0 comments

Comments

@LeoXJ978
Copy link

LeoXJ978 commented Dec 7, 2021

Issues and steps to reproduce

I use FlexboxLayoutManager with RecyclerView.Adapter to show short texts of roughly 4x20 on the screen at any time. To isolate the issue from data loading, I tested with a static set of items about 1000 loaded. As I scroll down, new items are shown from below and older items go out from the top. When I scroll fast, the views become very sluggish and jittery with abrupt stops in between. Interestingly, the sluggishness only seems to happen when I scroll down (scrolling up appears much better), even scrolling down again after having scrolled back up.

I have a RecyclerView within a LinearLayout, as

    <LinearLayout
        android:id="@+id/activity_words"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/words_list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="start"
            android:scrollbars="vertical"
            android:verticalSpacing="10dp" >
        </androidx.recyclerview.widget.RecyclerView>
    </LinearLayout>

Each item for the RecyclerView is defined as:

    <LinearLayout
        android:id="@+id/lauout"
        android:orientation="vertical"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="@dimen/list_padding">

        <TextView
            android:id="@+id/term"
            android:text="@{word.term}"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="start"
            android:textSize="@dimen/title_size"
            android:minWidth="50dp"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:textStyle="normal|bold"/>
    </LinearLayout>

In Java code,

                FlexboxLayoutManager layoutManager = new FlexboxLayoutManager(this);
                layoutManager.setFlexDirection(FlexDirection.ROW);
                layoutManager.setJustifyContent(JustifyContent.FLEX_START);
                layoutManager.setItemPrefetchEnabled(true);
                binding.wordsList.setLayoutManager(layoutManager);
                adapter.setTermSize(25f);
                binding.wordsList.setAdapter(adapter);

Expected behavior

I expect to see smoother scrolling

As I browsed through the code, without fully comprehending it, I found something I can't explain. In FlexboxLayoutManager.java, view cache is cleared while scrolling:

    @Override
    public int scrollVerticallyBy(int dy, RecyclerView.Recycler recycler,
            RecyclerView.State state) {
        if (isMainAxisDirectionHorizontal() ||
                (mFlexWrap == FlexWrap.NOWRAP && !isMainAxisDirectionHorizontal())) {
            int scrolled = handleScrollingMainOrientation(dy, recycler, state);
            mViewCache.clear(); 
            return scrolled;
        } else {
            int scrolled = handleScrollingSubOrientation(dy);
            mAnchorInfo.mPerpendicularCoordinate += scrolled;
            mSubOrientationHelper.offsetChildren(-scrolled);
            return scrolled;
        }
    }

I commented out the line mViewCache.clear(); in my local copy, then things appear drastically improved for me, at least scrolling down again becomes very smooth, though I don't know yet if it would cause other problems.

Version of the flexbox library

3.0.0

@LeoXJ978 LeoXJ978 changed the title Scroll vert sluggish and jittery with roughly 4x20 items on the screen Scroll view sluggish and jittery with roughly 4x20 items on the screen Dec 7, 2021
@LeoXJ978 LeoXJ978 changed the title Scroll view sluggish and jittery with roughly 4x20 items on the screen Scroll view sluggish and jittery Dec 7, 2021
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

No branches or pull requests

1 participant