![](/img/trans.png)
[英]On android 5.0,if a textview has set lineSpacingExtra, and has only one line text, the textview doesn't show linespacing
[英]How to set a TextView to display text in one line in Android
我已将TextView设置为显示。 我想在一行中显示正在执行的操作,例如:
9856243187 + 2457896123 - 214583
问题是,当输入到达TextView的边缘时 - 它会跳转到下一行。
那么,无论如何都要避免这种行为,并将输入保持在一行中,即使它离开了屏幕?
您应该在TextView标记中使用android:maxLines="1"
。 android:singleLine="true"
已弃用 。
android:singleLine="true"
是答案
更新:
android:singleLine
属性自API Level 3以来已被弃用,您可以使用
android:maxLines="1"
对于看到此问题的新用户,请使用android:singleLine="true"
。 忽略弃用警告。
根据此错误报告 ,设置android:maxLines="1"
可能会导致您的应用程序在android:ellipsize
中设置某些特定值时崩溃。 显然它会影响运行4.1 Jellybean到6.0.1 Marshmallow的大多数Android设备(固定在7.0牛轧糖中)。 根据您的设备,您的里程可能会有所不同。 但是,如果您作为开发人员瞄准各种设备,最好使用android:singleLine="true"
以防止崩溃。
在Textview中添加代码
android:singleLine="true"
谢谢家伙单行做了技巧,但我也不得不删除省略号:
android:ellipsize="none"
将TextView设置为singeline。
看看这个
如果要手动滚动单行内容,则应在HorizontalScrollView中使用TextView
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="16dp"
android:paddingTop="16dp"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="Single line text view that scrolls automatically if the text is too long to fit in the widget" />
</HorizontalScrollView>
这段代码对我有用:
android:singleLine="true"
你能试试这个吗?
<TextView
android:text="Single line text view that scrolls automatically if the text is too long to fit in the widget"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit ="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"
android:scrollHorizontally="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
希望这会帮助你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.