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,880
  • 4
  • 47
  • 52
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,747
  • 2
  • 30
  • 42
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
  • 881
  • 1
  • 8
  • 25
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
  • 8,100
  • 9
  • 63
  • 82