gpt4 book ai didi

android - 如何在水平滚动的单行 TextView 中设置长字符串

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:51:43 24 4
gpt4 key购买 nike

实际上我保留了一个 ScrollView 。在该 ScrollView 中,我在运行时设置了一个 TextView ,我想在该 TextView 中设置文本。我要设置的字符串的长度有些大,所以我无法在一行中获取字符串,但我可以获取两行或三行的字符串。我的 ScrollView 布局宽度大小是 250px。我不想超过那个大小......我的期望是如果字符串超过滚动大小,我希望在该 ScrollView 中看到该字符串作为单行,然后它应该在 TextView 中水平滚动。我尝试了一些功能,例如将水平滚动设置为 ScrollView 和 TextView ,但没有任何效果。请帮我解决这个问题。

你的,

s.kumaran.

最佳答案

您必须在 TextView 小部件中使用这两个 Xml 属性:

android:scrollHorizo​​ntally="true"

android:singleLine="true"

因此您的 xml 布局必须包含如下内容:

<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"/>

如果您使用代码创建您的TextView,您可以获得这些属性对应的方法,引用TextView documentation :

setHorizontallyScrolling(boolean)
setTransformationMethod(TransformationMethod)
setMarqueeRepeatLimit(int)

关于android - 如何在水平滚动的单行 TextView 中设置长字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1141651/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com