Android 防止 TextView 包裹在父级中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2507798/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Prevent TextView from wrapping in parent
提问by Jay Wick
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 is it impossible to have anything overflow from the screen?
如何防止 TextView 或任何视觉对象环绕到屏幕上,而是将它们从侧面切掉?是否有一些 XML 属性或代码可以做到这一点,或者屏幕上不可能有任何溢出?
For example, you have this:
例如,你有这个:
But you really want this:
但你真的想要这个:
Any ideas?
有任何想法吗?
回答by Pentium10
check out android:maxLines="1"
and if you want to add ending ...
add also android:ellipsize="end"
退房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"
was deprecated in API Level 3.
android:singleLine="true"
是在API级别3弃用。
回答by lbedogni
You're looking for android:singleLine="true"
.
您正在寻找android:singleLine="true"
.
回答by Robby Pond
Have you checked out android:scrollHorizontally. There is also a HorizontalScrollViewif that doesn't work.
你有没有检查过android:scrollHorizontally。如果不起作用,还有一个HorizontalScrollView。
回答by Eugene Kardash
And in java code it's:
在java代码中它是:
textView.setSingleLine();
回答by user2318360
textView.setHorizontallyScrolling(true);
worked for me.
textView.setHorizontallyScrolling(true);
为我工作。