Skip to content
New issue

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

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

Already on GitHub? # to your account

Flexbox showing a lot of items on the last line of maxLine #440

Open
guuilp opened this issue Jun 27, 2018 · 27 comments
Open

Flexbox showing a lot of items on the last line of maxLine #440

guuilp opened this issue Jun 27, 2018 · 27 comments

Comments

@guuilp
Copy link

guuilp commented Jun 27, 2018

Issues and steps to reproduce

I've been trying the new "maxLines" attribute, but its behavior is not like what I was expecting. Let's think about a list with 50 items, 4 per line: if I set the maxLIne to 3, the first and second line will show 4 items per line, but the third line will show 42 items, instead of 4. Is there a way to show 4 items in all lines and ignore the others 42?

Expected behavior

Ignore items after third line.

Version of the flexbox library

1.0.0

Link to code

        <com.google.android.flexbox.FlexboxLayout
            android:id="@+id/items_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:maxLine="3"
            android:paddingTop="20dp"
            android:paddingLeft="20dp"
            android:paddingRight="20dp"/>
@titooan
Copy link

titooan commented Jul 13, 2018

I am facing the same problem right now

@mecoFarid
Copy link

How did you get 4 items in the first two rows? Was it done with some attribute or FLexBox just randomly added 4 and pushed others into 3rd? Because I am looking for an attribute that defines max column count.

@guuilp
Copy link
Author

guuilp commented Jul 16, 2018

@mecoFarid it was "randomly", actually based on the smartphone screen width.

@redmanit
Copy link

same problem for me, maxLine is useless is this case. How did you guys overcome this issue?

@guuilp
Copy link
Author

guuilp commented Oct 18, 2018

@redmanit I did it manually... Stopped using maxLine, set height size to a fixed dp number and when the user clicks on expand, I change the height to wrap content.

@redmanit
Copy link

@guuilp so you need to calculate that fixed height size programmatically base on item height and padding, right?
Btw there are some other FlowLayout librarys support real maxLine feature not like this Google's one.

@manondidi
Copy link

same problem,please fix

@manondidi
Copy link

maxline is very important

@chdhy
Copy link

chdhy commented Apr 2, 2019

Same problem. I just want to show limited items by set maxline. Don't show more item if the item can not visible fully.Don't shrink the margin for the visible item of last line.thanks

@hugh114
Copy link

hugh114 commented May 21, 2019

Same problem. I want to scroll when item is out of the maxLine. thanks

@ukyo6
Copy link

ukyo6 commented Jul 5, 2019

same problem...still not fixed

@coding0man
Copy link

same problem

@ghost
Copy link

ghost commented Sep 21, 2019

Please fix that, it's very important feature for me and I think for many people too.
For now I restrict height of FlexboxLayout but it's dirty hack

@haiithust
Copy link

I work around it by custom function max line, inside the class FlexboxHelper

  1. in function isWrapRequired() remove condition relate to maxLine, it will be not wrap when you set maxLine
  2. Modify function calculateFlexLines() add condition if mFlexContainer.getMaxLine() == flexLines.size() break it.

You can find my change here, but sorry for code format style so you hard to read.
haiithust@9cbd2c9

@shaomaicheng
Copy link

I work around it by custom function max line, inside the class FlexboxHelper

  1. in function isWrapRequired() remove condition relate to maxLine, it will be not wrap when you set maxLine
  2. Modify function calculateFlexLines() add condition if mFlexContainer.getMaxLine() == flexLines.size() break it.

You can find my change here, but sorry for code format style so you hard to read.
haiithust@9cbd2c9

i do this,but do not work,my maxline is 3, but can see 5 lines

@haiithust
Copy link

I work around it by custom function max line, inside the class FlexboxHelper

  1. in function isWrapRequired() remove condition relate to maxLine, it will be not wrap when you set maxLine
  2. Modify function calculateFlexLines() add condition if mFlexContainer.getMaxLine() == flexLines.size() break it.

You can find my change here, but sorry for code format style so you hard to read.
haiithust@9cbd2c9

i do this,but do not work,my maxline is 3, but can see 5 lines

Hmm, could you try my repository https://github.com/haiithust/flexbox-layout

@Anthonyeef
Copy link

Have you tried add layout_flexShrink="0" to your flex item?

I learned this from the library unit test code: https://github.com/google/flexbox-layout/pull/424/files#diff-dfc1316fbcda7918a7dfadcea4a274a8R3982

@svanegas
Copy link

Have you tried add layout_flexShrink="0" to your flex item?

I learned this from the library unit test code: https://github.com/google/flexbox-layout/pull/424/files#diff-dfc1316fbcda7918a7dfadcea4a274a8R3982

@Anthonyeef this would help a bit, although if last element exceeds the width, it will be shown truncated anyways. It shouldn't be shown in this case.

@DarrelAeturnum
Copy link

Is this issue sorted ? or is there a work around for this ?

@desgraci
Copy link

desgraci commented Aug 5, 2021

bump for solution

@codefury
Copy link

Anyone listening here?
@thagikura @MGaetan89

@act262
Copy link

act262 commented Oct 18, 2021

Waiting fix it.

@act262
Copy link

act262 commented Oct 18, 2021

work around way 1:

layoutManager = object : FlexboxLayoutManager(requireContext()) { val fixMaxLine = 3 override fun getFlexLinesInternal(): MutableList<FlexLine> { val originList = super.getFlexLinesInternal() val size = originList.size if (size > fixMaxLine) { originList.subList(fixMaxLine, size).clear() } return originList } }

way 2:
dynamic recyclerView height and override canScrollVertically=false

@ararTP
Copy link

ararTP commented Nov 9, 2021

@act262 can you please post way 1 in java?

@preludezdev
Copy link

preludezdev commented Jan 9, 2022

For anyone who is still struggling, here is one trick idea.

Let's say you wanna make max line 3 flexbox layout with non truncated content on the last line.

  1. set FlexBoxLayout "height" to wrap_content and "layout_constraintHeight_max" to expected value of height when it is set to 3 lines (line heights + dividers)
  2. set flexLayout max lines 4
  3. then flexbox layout will show only three lines due to "layout_constraintHeight_max"

That's it!
Just be careful that your last line(ex. 4th line) will be thrown away.

@bangdinh
Copy link

bangdinh commented Apr 5, 2022

work around way 1:

layoutManager = object : FlexboxLayoutManager(requireContext()) { val fixMaxLine = 3 override fun getFlexLinesInternal(): MutableList<FlexLine> { val originList = super.getFlexLinesInternal() val size = originList.size if (size > fixMaxLine) { originList.subList(fixMaxLine, size).clear() } return originList } }

way 2: dynamic recyclerView height and override canScrollVertically=false

thank you!

@Mr-Zheng-yz
Copy link

work around way 1:

layoutManager = object : FlexboxLayoutManager(requireContext()) { val fixMaxLine = 3 override fun getFlexLinesInternal(): MutableList<FlexLine> { val originList = super.getFlexLinesInternal() val size = originList.size if (size > fixMaxLine) { originList.subList(fixMaxLine, size).clear() } return originList } }

way 2: dynamic recyclerView height and override canScrollVertically=false

nice work

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

No branches or pull requests