constraintlayout icon indicating copy to clipboard operation
constraintlayout copied to clipboard

Allow Flow to limit size of children with wrap_content

Open haluzpav opened this issue 5 years ago • 0 comments

Version: 2.0.4

Children with wrap_content don't fit inside the Flow when Flow's size doesn't match with parent ConstraintLayout. The Flow itself has correct size and position. Looks like max size of the children is the same as parent ConstraintLayout, instead of the Flow. That kind of makes sense, but I'd expect that the Flow would take over being parent, when computing size of its children.

When I use android:layout_width="0dp" on the children, then they all get squeezed on the first line.

I can get the expected behavior by setting child.maxWidth = flow.width on children at runtime but it's pretty cumbersome to get right. Maybe a new xml attribute on the Flow would be nice, if this is not a bug.

Example:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    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="match_parent">

    <androidx.constraintlayout.helper.widget.Flow
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="64dp"
        android:layout_marginEnd="32dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:flow_wrapMode="chain"
        app:flow_horizontalBias="1"
        app:constraint_referenced_ids="text1,text2,text3" />

    <TextView
        android:id="@+id/text1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:text="Super loooooooooooooooooooooooooooooooooooooooooooooooooong text" />

    <TextView
        android:id="@+id/text2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:text="Short text" />

    <TextView
        android:id="@+id/text3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:text="Super loooooooooooooooooooooooooooooooooooooooooooooooooong text" />

</androidx.constraintlayout.widget.ConstraintLayout>

Screenshot 2021-01-13 at 14 02 04

Expected: (mocked with LinearLayout)

Screenshot 2021-01-13 at 14 03 27

(screenshots from AS but it's the same at runtime)

haluzpav avatar Jan 13 '21 13:01 haluzpav