2

I try to implement layout from the picture. The problem is TextView - I need to wrap short text and ellipsize long one at the same time, but just can't achieve this:

  1. layout_width="wrap_content" - wrap is OK, but of course ellipsize is NOT (because no constraints applied, when wrap_content used)
  2. layout_width="0dp" - wrap not working
  3. layout_width="0dp" + constraintWidth_default="wrap" - wrap is OK, ellipsize is NOT

Also tried to play with constrainedWidth="true", but had no any visible effect.

enter image description here

Alexey Terekhov
  • 422
  • 4
  • 6

1 Answers1

2

Oh, did it! I used solution for similar problem (ConstraintLayout Chains and Text Ellipsis + Image on the Right) - it won't help until I excluded Button from the chain and remove Space which I used as "spring"!

Here is result - works exactly as in the picture.

<ConstraintLayout
  android:layout_width="match_parent"
  ...>

  <TextView
    android:id="@+id/text"
    android:layout_width="0dp" // enable constraints
    android:ellipsize="end"
    android:lines="1"
    app:layout_constraintHorizontal_chainStyle="packed" // keep text + icon side by side
    app:layout_constraintHorizontal_bias="0" // move text + icon to the left
    app:layout_constraintWidth_default="wrap" // make text as small to wrap text
    app:layout_constraintLeft_toLeftOf="parent" // chain starts
    app:layout_constraintRight_toLeftOf="@id/icon" // chain continues
    .../>

  <ImageView
    android:id="@+id/icon"
    app:layout_constraintLeft_toRightOf="@id/text" // chain continues
    app:layout_constraintRight_toLeftOf="@id/button" // chain ENDS!
    .../>

  <Button
    android:id="@+id/button"
    app:layout_constraintRight_toRightOf="parent" // move button to the right
    // PAY ATTENTION! There is no constraintLeft_toRightOf="icon" attribute!
    // because button must be out of chain
    .../>

</ConstraintLayout>
Alexey Terekhov
  • 422
  • 4
  • 6