如何使用水平滚动在单行中的文本视图中设置长字符串

Kum*_*mar 4 android

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

URS,

s.kumaran.

K_A*_*nas 5

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

android:scrollHorizontally="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"/>
Run Code Online (Sandbox Code Playgroud)

如果要使用代码创建TextView,可以获取这些属性的对应方法,请参阅TextView文档:

setHorizontallyScrolling(boolean)
setTransformationMethod(TransformationMethod)
setMarqueeRepeatLimit(int)
Run Code Online (Sandbox Code Playgroud)


ara*_*ams 3

尝试这个 ,,

TextView.setHorizo​​ntallyScrolling(true) TextView.setLines(1);

你在哪里添加了文本视图..在滚动视图中我们只能添加一个视图...