防止 TextView 包装在父级中 [英] Prevent TextView from wrapping in parent

查看:13
本文介绍了防止 TextView 包装在父级中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

例如,你有这个:

但你真的想要这个:

有什么想法吗?

推荐答案

查看 android:maxLines="1" 如果你想添加结尾 ...还添加 android:ellipsize="end"

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"在 API 级别 3 中已弃用.

这篇关于防止 TextView 包装在父级中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆