-1

For example we have combination of 2 words: "Firstword secondword". Textview have 1 line and it's width not big, so first word is visible, second to long to fit in rest space and it no visible: [Firstword______] How to achieve partial visibility of second word? Like this [Firstword secon] or [Firstword seco...](with ellipsize). Is it possible? I've seen in some topics that what I want is default behaviour when use ellipsize, but not in my case.

Edit: android:ellipsize="end" android:maxLines="1" work only in xml layout preview, but not work in runtime.

PravinCG
  • 7,688
  • 3
  • 30
  • 55
Anton Stukov
  • 128
  • 2
  • 12

3 Answers3

3

Found the solution.

This xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Helloooooooooooooooooooooo Wooooooooooooooooooooooooorld!"
        android:id="@+id/tv1"
        android:textColorLink="@android:color/holo_blue_dark"
        android:ellipsize="end"
        android:singleLine="true"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Helloooooooooooooooooooooo Wooooooooooooooooooooooooorld!"
        android:id="@+id/tv2"
        android:textColorLink="@android:color/holo_blue_dark"
        android:ellipsize="end"
        android:lines="1"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Helloooooooooooooooooooooo Wooooooooooooooooooooooooorld!"
        android:id="@+id/tv3"
        android:textColorLink="@android:color/holo_blue_dark"
        android:ellipsize="end"
        android:maxLines="1"/>
</LinearLayout>

render in design preview like enter image description here

OK, all ellipsizes work here. But on real device it look like enter image description here

android:singleLine="true" is only worked, in spite of it deprecated. Tested on 3 devices.

Anton Stukov
  • 128
  • 2
  • 12
1

Add these in your TextView

android:ellipsize="end" android:maxLines="1"

<TextView
   android:id="@+id/myTextView"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:ellipsize="end"
   android:maxLines="1"/>
PravinCG
  • 7,688
  • 3
  • 30
  • 55
0

if i understand what you want set to textView programmatically this:

textView.setEllipsize(TextUtils.TruncateAt.END);