0

I have a textview in xml file. When a text is set in java file, if the 2nd String is too long, for example: "Hello Worlddddddddddddddddddddddddddddddddddddddddddddd", the 2nd word is not visible. It should be only one line and should not use the android:singleLine How can I solve it? Thanks in advance for the help. :)

<TextView
    android:id="@+id/txtItemName"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:orientation="horizontal"
    android:maxLines="1"
    android:textColor="@color/white" />
inmyth
  • 8,620
  • 4
  • 44
  • 48
batista
  • 13
  • 6

3 Answers3

0

Use the XML below or refer to this SO article as this is what you really need.

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/textView"
        android:ellipsize="end"
        android:singleLine="true"
        android:gravity="right|center_vertical"
        android:maxLines="1"/>
Community
  • 1
  • 1
Christian Abella
  • 5,609
  • 2
  • 28
  • 41
0

if you without using singline, you can set height and weight. android:scrollHorizontally="false"

ex :

 <TextView
    android:id="@+id/text"
    android:text="@string/hello_world"
    android:layout_width="wrap_content"
    android:scrollHorizontally="false"
    android:layout_height="15dp"/>
QuestionAndroid
  • 802
  • 1
  • 6
  • 23
0

You can use elipsize property of textview

<TextView
android:id="@+id/txtItemName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:maxLines="1"
android:textColor="@color/white"
android:ellipsize="end" />
Kushal
  • 7,439
  • 7
  • 58
  • 76