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.

Flexbox not respecting children margins

See original GitHub issue

We’re on 0.2.2. We had wanted a slight margin (4dp) in between items in the flexbox, as well as between the lines when the flexbox wrapped the items. However, after trying multiple variations of applying margin to the items in the flexbox it did not seem to comply. Is this possible? We resorted to using another FrameLayout around the LinearLayout for padding, but what wondering if this is a bug or just not supported functionality within flexbox?

For example here is the item we were using in the flexbox. It was not respecting the layout_marginBottom or layout_marginRight on the LinearLayout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
       xmlns:tools="http://schemas.android.com/tools"
       xmlns:app="http://schemas.android.com/apk/res-auto"
       android:cropToPadding="false"
       android:clipToPadding="false"
       android:clipChildren="false"
       android:layout_height="32dp"
       android:layout_width="wrap_content"
       android:layout_marginBottom="10dp"
       android:layout_marginRight="10dp">

    <ImageView
        android:id="@+id/icon"
        android:layout_width="14dp"
        android:layout_height="14dp"
        android:layout_gravity="center_vertical"
        app:srcCompat="@drawable/ic_tag"
        android:tint="@color/bluey_grey"/>

    <TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:ellipsize="end"
        android:maxLines="1"
        android:paddingEnd="8dp"
        android:paddingLeft="8dp"
        android:paddingRight="8dp"
        android:paddingStart="8dp"
        android:textColor="@color/bluey_grey"
        android:textSize="14sp"
        tools:text="Conversations"/>

    <ImageView
        android:id="@+id/delete_icon"
        android:layout_width="10dp"
        android:layout_height="match_parent"
        android:layout_gravity="center_vertical"
        app:srcCompat="@drawable/ic_delete"/>

</LinearLayout>

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
barnaclejivecommented, Sep 13, 2017

I am having the same margin problem on programmatically generated child elements of FlexBoxLayout. I have opened a new issue #356

1reaction
lukasz-gosiewskicommented, Jun 1, 2017

Hello. It seems to me that I encountered the same problem. I’ve got flexbox layout as a container and I’m adding TextViews to it. However, despite setting margins programmatically they won’t appear in the layout. When switching to LinearLayout margins are working without problems. Is there any solution?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Flexbox preventing margins from being respected
The first thing to note is that margins have nothing to do with this problem. Margins are, in fact, being respected. They are...
Read more >
The peculiar magic of flexbox and auto margins - CSS-Tricks
Setting the margin property on a flex child will push the child away from that direction. Set margin-left to auto , the child...
Read more >
Flex Cheatsheet
The margin properties can be used to align items in a manner similar to, but more powerful than, what margins can do in...
Read more >
flex-basis - CSS: Cascading Style Sheets - MDN Web Docs
The flex-basis CSS property sets the initial main size of a flex item. It sets the size of the content box unless otherwise...
Read more >
Flexboxes growing bigger than parent / Padding not working
If it doesn't, that may be because your footer element exceeds the body. Then you can fix that by setting that to display:...
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