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

Support RecyclerView of which height is wrap_content

Open ywwynm opened this issue 7 years ago • 11 comments

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.

ywwynm avatar Aug 18 '17 14:08 ywwynm

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

thagikura avatar Aug 18 '17 14:08 thagikura

@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 avatar Aug 18 '17 15:08 ywwynm

@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".

ywwynm avatar Aug 18 '17 15:08 ywwynm

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?

thagikura avatar Aug 18 '17 17:08 thagikura

@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

ywwynm avatar Aug 19 '17 02:08 ywwynm

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 avatar Aug 21 '17 06:08 thagikura

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

ywwynm avatar Aug 21 '17 07:08 ywwynm

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>

Bringoff avatar Jan 02 '18 07:01 Bringoff

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

MedveDomg avatar Feb 01 '18 13:02 MedveDomg

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?

matheusfinatti avatar Jan 02 '19 08:01 matheusfinatti

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

soldierinwhite avatar Feb 27 '19 14:02 soldierinwhite