flexbox-layout: FlexboxLayoutManager did not display all items in NestedScrollView (item not displayed is hidden)
- 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
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 13
- Comments: 47 (1 by maintainers)
Links to this issue
Commits related to this issue
- Fix #420 : remove optimization for recyclerview calculation — committed to phcannessondkt/flexbox-layout by phcannesson 4 years ago
- fix #420 : remove calculation optimization in FlexboxHelper — committed to phcannessondkt/flexbox-layout by phcannesson 4 years ago
- Merge pull request #1 from phcannessondkt/fix/wrap_content_issue fix #420 : remove calculation optimization in FlexboxHelper — committed to phcannessondkt/flexbox-layout by phcannessondkt 4 years ago
I’ve looked into this and the issue seems to come from lines 620 - 629 in FlexboxHelper.
Commenting out this block does the trick :
I haven’t had the time to understand what this is supposed to optimize.
Hope this helps to solve the issue
still exist in 3.0.0, fix the issue please!!! upset!!
It’s been 2 years guys can we please find a solution to this. I am also having the same issue.
v1.0.0, Is there a solution to this issue? the same problem I encountered?
I still have this issue with v1.0.0. Either items are not showing with
setNestedScrolingEnabled(false), or the RecyclerView scrolls on its own withsetNestedScrolingEnabled(true)(see @syde0 's gif).A workaround may be to replace the RecyclerView with a simple
FlexboxLayoutand manuallyaddViewto it, but it’s not really ideal.Found solution.
I had to redo the screen without using pattern: NestedScrollView + RecyclerView (with setNestedScrolingEnabled(false)). Rebuild screen with only RecyclerView and complicated RecyclerView.Adapter. And all bottom items now are shown.
This way is more hard then just use NestedScrollView. But it works and now I think it’s more correct, because now items inside RecyclerView may be recycled.
Also I had problems with NestedScrollView and plenty count of items inside RecyclerView. Scroll was very slow and laggy. Rebuild screen with complicated adapter also helps.
The code:
This is a set of LayoutManager in code:
This is a screen RecyclerView.Adapter:
Inside layouts of Header and Footer set for parent ViewGroup:
android:layout_width="match_parent".And inside layout of Item set for parent ViewGroup:
android:layout_width="wrap_content".@syde0 @thagikura any solution for this issue? it’s still stuck from 2 years ago
Any updates on this?
It’s already 2023, and the problem still exists… There are only 2 options for me: copy the Flexbox library and remove the following code from the
FlexboxHelperor to completely rewrite my project, to get rid of
NestedScrollView.It’s very sad, that Google doesn’t maintain its own libraries
I have had the same problem. This issue reproducible when you put recycler view with FlexboxLayoutManager inside another recycler view. And FlexboxLayoutManager must have FlexDirection.ROW parameter. It cut my items after N row. Same problem in landscape mode too. If this issue can’t be solved, maybe someone can give a tip what combination of layout can reproduce (FlexBoxLayoutManager with a ROW) behaviour.
I confirm that the removal of the lines fix all my problems !