I tried to achieve scheme like this:
-------------------------------------------
| [text] [icon] |
-------------------------------------------
| [some more text] [icon] |
-------------------------------------------
| [super loooooooooooooooooooo...] [icon] |
-------------------------------------------
That is, I need my icon to always be attached to the text, but at the same time, if the text is too long, it has an ellipsis, and the icon does not crawl out of the screen. How can i do this?
My code:
<com.google.android.material.textview.MaterialTextView
android:id="@+id/tv_name"
style="@style/Bold"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="12dp"
android:background="@color/transparent"
android:ellipsize="end"
android:inputType="textPersonName"
android:lineHeight="34dp"
android:text="Hello how are youuuuuuuuuuuuuuuuu"
android:textColor="@color/gray"
android:textSize="32sp"
app:layout_constrainedWidth="true"
app:layout_constraintHorizontal_chainStyle="spread"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/toolbar" />
<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/btn_change_name"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:src="@drawable/ic_edit_button"
app:layout_constraintStart_toEndOf="@+id/tv_name"
app:layout_constraintTop_toBottomOf="@id/toolbar" />
I tried this option, the icon here is attached to the text, but it still goes off screen if the text is too long :(
Try this
This is also one way to add icon in last of text. In some cases it works properly.
Add this 2 line in your Textview