0

I want to display text (track title) and a view to right of the text. Like on the image below.

enter image description here

The view (image on the screenshot above) should always be visible. The view should be displayed right after the text if there is more room than necessary. The text should be truncated if there is not enough room.

The issue is: if the text is long enough the view is not displayed or displayed in smaller size.

Please don't recommend me to use text view with a drawableEnd attribute because the view not always will be an image view.

Here is the layout I use:

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="1">

    <TextView
        android:id="@+id/trackTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:lines="1"
        android:ellipsize="end"
        android:text="@string/placeholderTrackTitle"
        android:textSize="@dimen/track_name_height"
        android:textColor="@color/queue_text_color"
        android:layout_weight="0"/>

    <ImageView
        android:id="@+id/downloadedIcon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_downloaded"
        android:layout_gravity="center_vertical"
        android:layout_marginLeft="@dimen/queue_horizontal_margin"
        android:layout_marginRight="@dimen/queue_horizontal_margin"
        android:layout_weight="1"
        android:contentDescription="@string/downloaded_icon_description"/>
</LinearLayout>
Bobrovsky
  • 13,789
  • 19
  • 80
  • 130
  • You want the Text and image to be displayed, but the images should always be on the right hand side and the text on the left hand side, and if the text is too long then it should be truncated, is that what you looking for ? – Goofy Jun 30 '14 at 12:26
  • @Goofy almost. I want a text and a view (view may or may not be an image). All else is correct. – Bobrovsky Jun 30 '14 at 12:30
  • Please check my answers below, it might help you – Goofy Jun 30 '14 at 12:33
  • Can you please know me what type of view you have to shown after text like your statement"the view not always will be an image view". – Haresh Chhelana Jun 30 '14 at 12:49
  • @Haresh it can be an image view or a circular progress bar. – Bobrovsky Jun 30 '14 at 12:51

2 Answers2

0

Use the maxWidth attribute on the TextView and ellipsize the text in case of overflow.

edit: or MaxLength, MaxLines, or MaxEms, whichever works better for your purposes

Robin Eisenberg
  • 1,836
  • 18
  • 26
-2

ok, there are few solutions that i have used and it works good.

Check the below one:

1) Android: Something better than android:ellipsize=“end” to add “…” to truncated long Strings?

2) How to truncate TextView, and then add ellipsis in Android

Community
  • 1
  • 1
Goofy
  • 6,098
  • 17
  • 90
  • 156
  • It looks like neither of the links has anything to do with view positioning issue. – Bobrovsky Jun 30 '14 at 12:43
  • @Bobrovsky In your question `The issue is: if the text is long enough the view is not displayed or displayed in smaller size.` i have answered to that – Goofy Jun 30 '14 at 12:45
  • I am afraid you are wrong. You propose to use ellipsize feature but I am already using it. – Bobrovsky Jun 30 '14 at 12:48
  • hmmmm, in that case use weights and fix the view size and proceed, which will solve your problem – Goofy Jun 30 '14 at 12:50