如何防止 TextView 或任何视觉对象环绕到屏幕上,而是将它们从侧面切掉?是否有一些 XML 属性或代码可以执行此操作,或者屏幕上不可能有任何溢出?

例如,你有这个:

text being wrapped

但你真的想要这个:

text being cropped

有任何想法吗?

有帮助吗?

解决方案

检查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"在API级别3弃用

其他提示

您正在寻找android:singleLine="true"

你结帐了吗 android:水平滚动. 。还有一个 水平滚动视图 如果那不起作用。

和在Java代码是:

textView.setSingleLine();

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top