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

Support RecyclerView of which height is wrap_content #349

Open
ywwynm opened this issue Aug 18, 2017 · 11 comments · May be fixed by #507
Open

Support RecyclerView of which height is wrap_content #349

ywwynm opened this issue Aug 18, 2017 · 11 comments · May be fixed by #507
Labels

Comments

@ywwynm
Copy link

ywwynm commented Aug 18, 2017

If the RecyclerView's height is wrap_content, only one line of items will be shown and we should scroll the RecyclerView to see the second line(FlexDirection is ROW). It was said that if FlexWrap is set to WRAP, multiple lines will be shown but the fact is not like that. Please support this, thanks.

@thagikura
Copy link
Contributor

I thought it's supported. Could you share your XML configuration for the RecyclerView and the settings for the FleboxLayoutManager?

@ywwynm
Copy link
Author

ywwynm commented Aug 18, 2017

@thagikura My layout(for a BottomSheet and is included in main layout) is:

<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  app:behavior_peekHeight="56dp"
  app:layout_behavior="@string/bottom_sheet_behavior">

  <android.support.v7.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

</RelativeLayout>

And item's layout:

<FrameLayout
  android:layout_width="wrap_content"
  android:layout_height="42dp">

  <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center" />

</FrameLayout>

And settings for FlexboxLayoutManager(in kotlin and actually settings are default ones):

val flm = FlexboxLayoutManager(this)
rv.layoutManager = flm

@ywwynm
Copy link
Author

ywwynm commented Aug 18, 2017

@thagikura Actually the bug is: some last line won't be shown under some circumstances(I'm still working on finding what these conditions are), not "only shows first line".

@thagikura
Copy link
Contributor

Thanks for the info. I guess the height may be constrained by another component.
When the last line isn't shown, is the bottom sheet fully shown or is it in its peek position?

@ywwynm
Copy link
Author

ywwynm commented Aug 19, 2017

@thagikura I think I find the reason causes the bug: if the item of RecyclerView is a TextView having a compound drawable, then the display will not be correct. However, if I replace it with an ImageView and a TextView inside a LinearLayout to achieve same effect, then the RecyclerView will show all items.
Please import attached demo project below and take a look at the bug. Thank you.
FlexboxLayoutManagerBug.zip

@thagikura
Copy link
Contributor

thagikura commented Aug 21, 2017

Thanks for creating the test project.
Confirmed the weird behavior, the issue seems to be caused if any compound drawables are included in the item in the RecyclerView.

In the initial call of the onLayoutChidlren, the width of the TextViews haivng a compound drawable seems to be calculated as if they don't have the compound drawable. As a result, the number of flex lines is shorter than expected.

Let me mark this as a bug.

@thagikura thagikura added the bug label Aug 21, 2017
@ywwynm
Copy link
Author

ywwynm commented Aug 21, 2017

@thagikura Thanks. I will wait for the fix but currently the LinearLayout stuff is adoptable.

@Bringoff
Copy link

Bringoff commented Jan 2, 2018

Looks like I have the same behavior when TextView in ListItem has custom background (like this in my case:)

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="@color/color_tag_background" />
    <stroke
        android:width="1dp"
        android:color="@color/color_tag_border" />
    <corners android:radius="12dp" />
</shape>

@MedveDomg
Copy link

if we have three items at one line with linear layout manager then change for flex layout manager, only two items will be shown on and third one will be on next line

@matheusfinatti
Copy link

Also happens when using android.support.design.chip.Chip.
In some instances the FlexboxLayoutManager is able to wrap the list of items and create a new line, however in some conditions it doesn't and the item is shown after scrolling the recyclerView. Does anyone know a workaround for this?

@soldierinwhite
Copy link

I am seeing the same bug with items that have a constraintlayout parent, with textview and imagebutton as children.

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

Successfully merging a pull request may close this issue.

6 participants