0

I have a TextView

<TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="3"
    android:layout_gravity="center_vertical"
    android:layout_marginLeft="8dp"
    android:layout_marginStart="8dp"
    android:ellipsize="middle"
    android:maxLines="2"
    />

Notice maxLines="2". now i always want that the 2nd line will be a String that represents the date.

for example (very simplified, i'm actually using SpannableStringBuilder):

 String s = "this string is longer than 1 line"
 s += "\n" + "Today, January, 2038"

Now i want to make sure that the date will be present alone at the second row and the TextView rep will be something like:

"this string is longer than...

Today, January, 2038"

is it possible?

royB
  • 12,779
  • 15
  • 58
  • 80

1 Answers1

-1

First you can try to remove the attribute android:ellipsize="end" and see what happens. Otherwise, I suggest you to have separate TextView for the date. It is best practice to separate those, it will allow you to give different style to each TextView later on.

Nimrod Dayan
  • 3,050
  • 4
  • 29
  • 45
  • well i should left my `p.s` comment that say that i know i can use 2 `TextView` but not looking for this kind of solution. by the way don't sure it's best practice and for sure it will complicate my ViewGroup more than is should. the `Style` : this is why i use SpannableStringBuilder. thanks for your answer – royB Jan 25 '15 at 11:46
  • 1
    according to my understanding, the way TextView work is that it fits the text according to the boundaries of its height and width. If the width is too short to display the text is one line, it will overflow to another line. `android:maxLines` attribute only tells it to limit the overflowing lines to X. you can then use `android:ellipsize` which will "truncate" the text and for instance add "..." in the end, indicating that there's more text. imo, you have no other option, but to use 2 TextViews. And I don't think line breaks, such as, "\n", have any affect on TextViews – Nimrod Dayan Jan 25 '15 at 11:50
  • `android:ellipsize="middle"` was supposed to do the trick, but it wont... /-: and of course \n have effect... try it – royB Jan 25 '15 at 11:54