8

I have read a few of the other threads here with similar concerns, but none of their answers seemed to work for me.

Can't get ellipsis to work on Android

Android: Something better than android:ellipsize="end" to add "..." to truncated long Strings?

I have a Relative Layout with 2 elements, a text view and an image view. I need the text view to be 1 line and to truncate about 5sp short of the image view 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 was attempting to apply a margin left to the Image View to force the text view to its left to truncate by as many sp as I put in the margin.

The code above would truncate the text view to a single line and add (...) but only to the end of that line; irrespective of the ImageView to it's right, regardless of whatever margin I apply to it. The Image View appears above the text. I figured this may be due to them being in a relative layout.

Any help in figuring out how to make the text view respect the margin/space taken up by the image view would be greatly appreciated.

Community
  • 1
  • 1
wapples
  • 183
  • 2
  • 12
  • I had to edit some explicit language in the code, forgive me for having to repost this. – wapples Oct 08 '12 at 20:16
  • You can edit in existing posts. – Andrew Barber Oct 08 '12 at 20:18
  • I didin't want there to be a record of the language in the edit log, soI figured the best course was to delete and repost all together. – wapples Oct 08 '12 at 20:18
  • Oh; if you actually deleted the old one, that's not so bad, then. (Don't make deleting posts a habit, by the way; it's meant for rare cases. Using it too often can cause some moderation flags to go off on your account) – Andrew Barber Oct 08 '12 at 20:19
  • I would recommend explaining what you mean by "this didn't appear to be working", and some about why those other questions did not help you. – Andrew Barber Oct 08 '12 at 20:20
  • I had no idea that might be an issue. I did delete it, but I will be careful in the future. Thank you. – wapples Oct 08 '12 at 20:21

1 Answers1

6

I believe what you want to do is to first place the image view (with margins) and then set the text to align to the left border and to be placed to the leftOf the image.

Tobias Ritzau
  • 3,327
  • 2
  • 18
  • 29