flexbox-layout icon indicating copy to clipboard operation
flexbox-layout copied to clipboard

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

Open syde0 opened this issue 6 years ago • 47 comments

  • [x] I have searched existing issues and confirmed this is not a duplicate

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

syde0 avatar Mar 30 '18 02:03 syde0

Some UPDATE

Just noticed that the other items that are not displayed in the list was hidden outside it's view. When i scrolled that category list (not the entire page and i have just realized that using setNestedScrolingEnabled(false) will only allow smooth scrolling of its parent page, not disable the scrolling of that particular list) my other items are displayed.

Since I just found this, this seems to be the same issues as issue 400, but i don't think there's any concrete answer in it.

As i said earlier, using FlexDirection.COLUMN will display all my item, but i'm having trouble with FlexDirection.ROW as it seems to display items within it's own list height , I'm not sure what to do here..

syde0 avatar Mar 30 '18 07:03 syde0

Hi, I would like to help solve this issue. Project admin(@androhi,@thagikura) please let me know whether I can go ahead to fix this and assign this issue to me so that I can begin the process. Thanks.

ghost avatar Apr 01 '18 15:04 ghost

Hi Monika thank you for replying. Were you able to replicate the problem i'm facing? And it seems you have found a solution for this, so is it okay for me to ask whats happening here? Again thanks for replying :))

syde0 avatar Apr 01 '18 15:04 syde0

Thanks for filing the issue, sorry for the delayed comment.

I think this may be same as #400 as @syde0 says,

@MONIKA-KUMAR-JETHANI, It's great if you can make a pull request for it! I don't think I have bandwidth to work on issue at the moment.

thagikura avatar Apr 02 '18 06:04 thagikura

Thank you very much for replying @thagikura & @MONIKA-KUMAR-JETHANI, looking forward for the next update :))

syde0 avatar Apr 02 '18 07:04 syde0

@syde0 ,@thagikura, I will look into this and reply asap.

ghost avatar Apr 02 '18 18:04 ghost

@syde0 Are you setting 'setFlexWrap' anywhere?

ghost avatar Apr 07 '18 16:04 ghost

@MONIKA-KUMAR-JETHANI no sir, the only thing i did was setting up the Flexboxlayoutmanager

syde0 avatar Apr 07 '18 16:04 syde0

@syde0 Could you please share the project?

ghost avatar Apr 07 '18 16:04 ghost

@MONIKA-KUMAR-JETHANI my apologies sir but i could not share the project, I already shared how I used the manager and the layout above. Is there a problem that you encountered from your side sir?

syde0 avatar Apr 07 '18 16:04 syde0

@syde0 Please use "rlvCategory.setNestedScrollingEnabled(true)" and also set android:scrollbars="vertical" for the android.support.v4.widget.NestedScrollView element. rlvCategory.setNestedScrollingEnabled(true) will show you all the items and android:scrollbars="vertical" will bring up a scrollbar and make the scrolling intuitive. I have tried a POC using some of the code that you've shared and this works.Please let me know if this helps and please refer to me as madam and not sir.

ghost avatar Apr 07 '18 17:04 ghost

@MONIKA-KUMAR-JETHANI my apologies madam. Ok I will try this one, thank you again for responding.

syde0 avatar Apr 07 '18 17:04 syde0

@syde0 Could you please try that and let me know. @thagikura I have figured out a solution for this problem. Once @syde0 is satisfied, please let me know how this bug could be closed. Do I need to raise a pull request for it?

ghost avatar Apr 08 '18 14:04 ghost

@monika my apologies but im currently not with my work station, i will apply your solutions asap by morning, to be honest i cant stand still either lol, sorry for making you wait..

syde0 avatar Apr 08 '18 14:04 syde0

@thagikura Could you please add me as an assignee to this issue?

ghost avatar Apr 08 '18 14:04 ghost

Hi @MONIKA-KUMAR-JETHANI, sorry for making you wait, i did as you said above, it does work in a term of it will display all my list by scrolling, but it does not work as it should have inside a scrollview like when i used a FlexDirection.COLUMN or LinearLayoutManager while setting up setNestedScrollingEnabled(false),

Your suggestion will allow my scrollview to scroll to the bottom while also allow my recyclerview to scroll within its own content. The result will be weird for user experience side which I would like to avoid. Here is the result that i have. Please ignore the date design lol..

But your suggestion does show FlexDirection(FlexDirection.ROW) can be scroll to show more of it content within its own height..

syde0 avatar Apr 09 '18 02:04 syde0

@syde0 I will check this once more and reply.

ghost avatar Apr 28 '18 18:04 ghost

@MONIKA-KUMAR-JETHANI thank you very much madam, i really appreciate your help, sorry for the late reply..

syde0 avatar May 03 '18 13:05 syde0

Hey guys @syde0 @MONIKA-KUMAR-JETHANI ! Do you have any update on this issue? Looks like it appears if you put a RecyclerView with Flexbox layout manager inside another RecyclerView.

KirillChalenko avatar May 24 '18 12:05 KirillChalenko

I still have this issue with v1.0.0. Either items are not showing with setNestedScrolingEnabled(false), or the RecyclerView scrolls on its own with setNestedScrolingEnabled(true) (see @syde0 's gif).

A workaround may be to replace the RecyclerView with a simple FlexboxLayout and manually addView to it, but it's not really ideal.

herbeth1u avatar Jul 01 '18 10:07 herbeth1u

Is not a good practice to put a recycler view inside a nestedscroll view but some times is required speccially if you are using bottom sheet from google ...

CristianCardosoA avatar Oct 23 '18 23:10 CristianCardosoA

any progress for this issue? i face this problem also

tuinui avatar Apr 26 '19 05:04 tuinui

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

bakonMa avatar Jun 04 '19 04:06 bakonMa

v2.0.1 - the same issue. Any news regarding this?

nzakharchenko avatar Jan 31 '20 10:01 nzakharchenko

v2.0.1 - encounter the same issue, any news about? setNestedScrolingEnabled(true) when inside a nestedscrollview the content cut at the end. Note that when it change from row to column, it will show all the elements, the problem only happens when it is in column mode.

AkiraSuguiura avatar Apr 23 '20 14:04 AkiraSuguiura

Any updates on this?

kidouchi avatar Jul 31 '20 02:07 kidouchi

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

phcannessondkt avatar Aug 04 '20 07:08 phcannessondkt

Same thing... If use NestedScrollView + recyclerView (with setNestedScrolingEnabled(false)) + and FlexDirection.ROW. Items not show from bottom. You fix this?

SerjantArbuz avatar Aug 12 '20 16:08 SerjantArbuz

It happens to me , I have to manually calculate the height again. (version 2.0.1)

shineyue avatar Aug 13 '20 07:08 shineyue

same problem happen to me.

NaqiControl avatar Aug 20 '20 18:08 NaqiControl