question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FlexboxLayoutManager with FlexboxItemDecoration cause item height incorrent

See original GitHub issue

Issues and steps to reproduce

Expected behavior

i expect the height of every items is the same, and has correct ItemDecoration

Version of the flexbox library

1.0.0

Link to code

  • Result image

  • Step 1 set RecyclerView margin

<android.support.v7.widget.RecyclerView
            android:id="@+id/list"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="113dp"
            android:scrollbars="none"
            android:layout_marginLeft="30dp"
            android:layout_marginRight="30dp"
            android:overScrollMode="never"/>
  • Step 2 add two RecyclerView with FlexLayoutManager, ( And all of them using the same code, Only the datasources is diffrent )

  • Step 3 add FlexboxItemDecoration for the two flexBoxRecyclerViews

private fun init() {
        if (layoutManager == null ) {
            val flexboxLayoutManager = FlexboxLayoutManager(context, FlexDirection.ROW)
            layoutManager = flexboxLayoutManager
            initDecoration()
            isNestedScrollingEnabled = false
        }
        overScrollMode = View.OVER_SCROLL_NEVER
        isHorizontalScrollBarEnabled = false
        isVerticalScrollBarEnabled = false
        adapter = mAdapter
    }

    private fun initDecoration() {
        val decoration = FlexboxItemDecoration(context)
        val drawable = GradientDrawable().apply {
            setSize(Utils.dp2px(context, 15f), Utils.dp2px(context, 15f))
        }
        decoration.setDrawable(drawable)
        decoration.setOrientation(FlexboxItemDecoration.BOTH)
        addItemDecoration(decoration)
    }
      the item layout for each
<com.xinpinget.xbox.widget.textview.AwesomeTextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="24dp"
        android:text='@{item.text}'
        android:textSize="12sp"
        android:paddingLeft="9dp"
        android:paddingRight="9dp"
        app:radius="4dp"
        android:maxWidth="122dp"
        android:singleLine="true"
        android:ellipsize="end"
        android:gravity="center_vertical"/>

Test by myself

  i exchange the datasource with the top and bottom, the bottom also be incorrent, and i dont think is my code bad....

Although solved by add margin for item, but i think add item decoration is the best way, hope your answer, thanks

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:6
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

11reactions
kaustav07commented, Aug 14, 2020

Any plan to fix this issue? it still exists in 2.0.1

9reactions
eliotjohnsoncommented, Jan 7, 2019

I am experiencing a similar issue as well. Seems related to #246 , but that was supposedly fixed.

I’m using my own drawable to achieve custom padding:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <size android:width="8dp"
        android:height="12dp"/>
    <solid android:color="@android:color/transparent"/>
</shape>

and adding the decoration to my RecyclerView(s):

// Decoration for spacing between elements
val paddingDecoration = FlexboxItemDecoration(context)
paddingDecoration.setDrawable(resources.getDrawable(R.drawable.flex_divider))
filterSectionRecyclerView.addItemDecoration(paddingDecoration)

For certain content that comes very close to filling the entire row width, the wrapping is wrong:

wrong padding

If I adjust the padding slightly so it doesn’t come as close to full row width, the wrapping works as expected:

expected behavior

Read more comments on GitHub >

github_iconTop Results From Across the Web

RecyclerView items with different heights with ... - Stack Overflow
I want to use a recycleviewer with FlexboxLayoutManager. Every item normally having their own height depending on their content.
Read more >
Recyclerview Items With Different Heights With ... - ADocLib
Hi I am using RecyclerView with FlexboxLayoutManager for layoutManager.setFlexDirectionFlexDirection.ROW; RecyclerView height is. Flexboxlayoutmanager With ...
Read more >
Flexbox Based Responsive Equal Height Blocks With ...
It provides almost no time gap between initially wrong and correctly laid out layout look. In JavaScript solution case it takes time to...
Read more >
Flexbox for Android – Creating a CenterFlowAdapter
FlexboxLayout and FlexboxLayoutManager are included; both are very ... here isn't just a grid layout that will center the last row of items....
Read more >
Keep the Footer at the Bottom: Flexbox vs. Grid
This method relied on setting an explicit footer height, ... one weird trick will cause the margin to fill any space between the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found