question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FlexboxLayoutManager did not display all items in NestedScrollView (item not displayed is hidden)

See original GitHub issue

Issues and steps to reproduce

Hello, I’m using a default configuration of FlexboxLayoutManager but does not able to display all items, from my log i can only receive 45/60 items (i’ve listed variations of results in ‘Expected Behavior’ column), I looked into issue 286 and 208 (and others) and it seems that they are all solved with latest version, as you can see below i’m using the latest version but i’m facing this issue, I apologized if i missed anything on my part, any suggestions and helps are really appreciated 😃, my configurations are as follows,

I’m using a default FlexboxLayoutManager such as this:

adapterCategory = new AdapterCategory(getActivity(), categories, this);
        flmCategory = new FlexboxLayoutManager(getActivity());
        rlvCategory.setAdapter(adapterCategory);
        rlvCategory.setLayoutManager(flmCategory);
        rlvCategory.setNestedScrollingEnabled(false);
        rlvCategory.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                if (adapterCategory.holdersG.size() > 0) {
                    switchAllCategories.setChecked(true);
                    adapterCategory.setAllCategoriesTrue();
                    rlvCategory.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                }
            }
        });

with a layout like this for recyclerview (rlvCategory), as you can see i’m using it under LinearLayout and NestedScrollView:

<android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="16dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <TextView ... />

            <TextView ... />

            <android.support.v7.widget.RecyclerView ... />

            <RelativeLayout ... />

            <android.support.v7.widget.RecyclerView
                android:id="@+id/rlvCategory"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                tools:listitem="@layout/row_search_category" />
        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>

with something like this in my item layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="6dp">
    <ToggleButton
        android:id="@+id/tbCategory"
        style="?attr/borderlessButtonStyle"
        android:layout_width="wrap_content"
        android:layout_height="35dp"
        android:background="@drawable/background_rounded_gray_full"
        android:paddingEnd="16dp"
        android:paddingStart="16dp"
        android:textAllCaps="false"
        android:textColor="@android:color/black"
        android:textSize="12sp" />
</RelativeLayout>

Expected behavior

I’m expecting my list to display all the items from my adapter but it does not display all of them. Currently my adapter would have 60 items and this is what i test:

  • If I use flmCategory.setFlexDirection(FlexDirection.ROW);, list will display up to 45 items.

  • If I use flmCategory.setFlexDirection(FlexDirection.ROW); and set a fix height and remove paddings on my item layout, list will display up to 53 items.

  • If I use flmCategory.setFlexDirection(FlexDirection.COLUMN);, list will display all 60 items.

Version of the flexbox library

Im using the latest 'com.google.android:flexbox:0.3.2' version

Link to code

Please link to the code we can use to reproduce this issue. A complete project we can build/run is preferred, if you can’t provide one, please show us relevant code

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:9
  • Comments:44 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
phcannessondktcommented, Aug 4, 2020

I’ve looked into this and the issue seems to come from lines 620 - 629 in FlexboxHelper.

Commenting out this block does the trick :

if (sumCrossSize > needsCalcAmount && reachedToIndex) {
    // Stop the calculation if the sum of cross size calculated reached to the point
    // beyond the needsCalcAmount value to avoid unneeded calculation in a
    // RecyclerView.
    // To be precise, the decoration length may be added to the sumCrossSize,
    // but we omit adding the decoration length because even without the decorator
    // length, it's guaranteed that calculation is done at least beyond the
    // needsCalcAmount
    break;
}

I haven’t had the time to understand what this is supposed to optimize.

Hope this helps to solve the issue

5reactions
bakonMacommented, Jun 4, 2019

v1.0.0, Is there a solution to this issue? the same problem I encountered?

Read more comments on GitHub >

github_iconTop Results From Across the Web

RecyclerView that does not scroll and shows all items
If you are using RecyclerView inside ScrollView then Replace ScrollView with NestedScrollView and enable the nested scrolling
Read more >
RecyclerView with NestedScrollView best practices and how ...
A RecylerView inflates a customized list of items. This list can have either all similar layouts or multiple distinct layouts. To use ...
Read more >
flexbox-layout首页、文档和下载 - Flexbox for Android - OSCHINA ...
#420, FlexboxLayoutManager did not display all items in NestedScrollView (item not displayed is hidden), by syde0 2022-10-28 ...
Read more >
NestedScrollView in Android with Example - GeeksforGeeks
not showing any kind of deceleration in its growth. ... inside LinearLayout add two TextView to display the strings which are created inside ......
Read more >
listview inside nested scrollview doesn't show the list item ...
By default the <android.support.v4.widget.NestedScrollView> does not create this attribute when dragged from the palette nor is it a attribute exposed in the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found