阻止TextView包装在父级中

时间:2022-12-16 22:25:51

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:

例如,你有这个:

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

正在包装的文字http://i43.tinypic.com/6xwyzd.jpg

But you really want this:

但你真的想要这个:

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

正在裁剪的文字http://i43.tinypic.com/i5rc51.jpg

Any ideas?

有任何想法吗?

5 个解决方案

#1


61  

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 Level 3中已弃用。

#2


8  

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

你正在寻找android:singleLine =“true”。

#3


4  

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

你有没有检查过android:scrollHorizo​​ntally。如果不起作用,还有一个Horizo​​ntalScrollView。

#4


0  

And in java code it's:

在java代码中它是:

textView.setSingleLine();

#5


0  

textView.setHorizontallyScrolling(true); worked for me.

textView.setHorizo​​ntallyScrolling(真);为我工作。

#1


61  

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 Level 3中已弃用。

#2


8  

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

你正在寻找android:singleLine =“true”。

#3


4  

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

你有没有检查过android:scrollHorizo​​ntally。如果不起作用,还有一个Horizo​​ntalScrollView。

#4


0  

And in java code it's:

在java代码中它是:

textView.setSingleLine();

#5


0  

textView.setHorizontallyScrolling(true); worked for me.

textView.setHorizo​​ntallyScrolling(真);为我工作。