Prevent TextView from wrapping in parent

前端 未结 5 1972
耶瑟儿~
耶瑟儿~ 2020-12-13 18:19

How do I prevent a TextView, or any visual object, from wrapping to the screen and instead have them chopped off the sides? Is there some XML attribute or code to do this or

相关标签:
5条回答
  • 2020-12-13 18:43

    check out android:maxLines="1" and if you want to add ending ... add also android:ellipsize="end"

    <TextView
       android:id="@+id/name"
       android:text="i want this to crop not wrap"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:maxLines="1"
       android:ellipsize="end" />
    

    android:singleLine="true" was deprecated in API Level 3.

    0 讨论(0)
  • 2020-12-13 18:43

    You're looking for android:singleLine="true".

    0 讨论(0)
  • 2020-12-13 18:50

    Have you checked out android:scrollHorizontally. There is also a HorizontalScrollView if that doesn't work.

    0 讨论(0)
  • 2020-12-13 18:55

    And in java code it's:

    textView.setSingleLine();
    
    0 讨论(0)
  • 2020-12-13 18:55

    textView.setHorizontallyScrolling(true); worked for me.

    0 讨论(0)
提交回复
热议问题