代码之家  ›  专栏  ›  技术社区  ›  Jay Wick

防止textView在父级中换行

  •  35
  • Jay Wick  · 技术社区  · 16 年前

    如何防止文本视图或任何视觉对象包装到屏幕上,而不是将它们从侧面切掉?是否有一些XML属性或代码来执行此操作,或者不可能有任何内容从屏幕溢出?

    例如,您有:

    text being wrapped http://i43.tinypic.com/6xwyzd.jpg

    但你真的想要这样:

    text being cropped http://i43.tinypic.com/i5rc51.jpg

    有什么想法吗?

    5 回复  |  直到 7 年前
        1
  •  66
  •   Jeremy Rajan Balana    9 年前

    退房 android:maxLines="1" 如果你想加上结尾 ... 还添加 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" 是 deprecated in API Level 3 .

        2
  •  8
  •   lbedogni    16 年前

    你在找 android:singleLine="true" .

        3
  •  5
  •   Robby Pond    16 年前

    你退房了吗 android:scrollHorizontally . 还有一个 HorizontalScrollView 如果那不起作用。

        4
  •  1
  •   Eugene Kardash    11 年前

    在Java代码中:

    textView.setSingleLine();
    
        5
  •  0
  •   Paresh Mayani jeet    10 年前

    textView.setHorizontallyScrolling(true); 为我工作。