How to crop TextView and then add ellipsis in Android

I read several other topics with similar problems, but none of their answers worked for me.

Unable to get ellipsis for working on Android

Android: something better than android: ellipsize = "end" to add "..." for truncated long lines?

I have a relative layout with two elements, a text view and an image view. I need the text view to be 1 line and truncate about 5 seconds less than the image and apply ellipsis to the end of the text.

<RelativeLayout android:id="@+id/title_close" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="5sp"> <TextView android:id="@+id/" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:textSize="10sp" android:textColor="#FFFFFF" android:text="title" android:maxLines="1" android:ellipsize="end"/> <ImageView android:id="@+id/" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_marginRight="5sp" android:layout_marginLeft="5sp" android:background="@drawable/home"/> </RelativeLayout> 

In the above code, I tried to apply the marker left to the image to force the text representation to the left of it to truncate by as much sp as I put in the field.

The code above truncates the text representation into one line and adds (...), but only to the end of this line; regardless of the ImageView to it, no matter what area applies to it. The image is displayed above the text. I figured this could be due to relative layout.

Any help in figuring out how to make the text view respected margin / space occupied by the image presentation would be greatly appreciated.

+7
source share
1 answer

I believe that you want to first place the image (with margins) and then set the text to align to the left border and put it to the left on the image.

+6
source

All Articles