constraintlayout
constraintlayout copied to clipboard
Flow views getting clipped
I have a horizontal chain flow of programatically added items (key-value pairs).
<androidx.constraintlayout.helper.widget.Flow
android:id="@+id/flow"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:orientation="horizontal"
app:flow_horizontalAlign="start"
app:flow_horizontalBias="0"
app:flow_horizontalGap="8dp"
app:flow_horizontalStyle="packed"
app:flow_verticalGap="8dp"
app:flow_wrapMode="chain"
app:layout_constraintEnd_toEndOf="@id/endGuideline"
app:layout_constraintStart_toStartOf="@id/startGuideline"
app:layout_constraintTop_toBottomOf="@id/title" />
Each item is added with the following layout params:
ConstraintLayout.LayoutParams(
ConstraintLayout.LayoutParams.WRAP_CONTENT,
ConstraintLayout.LayoutParams.WRAP_CONTENT
).apply {
constrainedWidth = true
constrainedHeight = true
}
When I add an item with a lot of text, the view is being clipped at the bottom (screenshot 1).
Everything is working fine if a flow has no horizontal paddings/margins, and horizontally constrained to the parent (Screenshot 2).
Seems like large views are getting measured wrong.
Demo project: constraint-layout-issue activity_main.xml item_view.xml MainActivity.kt
❌ Screenshot 1 – flow constrained to guidelines (start/end=16dp), large views getting clipped.
✅ Screenshot 2 – flow constrained to the parent, everything is fine.