在textView android中移动文本

use*_*569 14 android

我想问你textview是否有任何选项,当我有太长的文本时,例如文本有30 dp而textview有15 dp我想显示从左上角移动到右边并返回到开始和再次的文本.像动画一样的东西.我想用户看到所有文字.像自动滚动的东西.

编辑:我怎么能在代码中,而不是xml?

Vin*_*hwa 11

一个例子 -

在XML中:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView
        android:id="@+id/tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:ellipsize="marquee"
        android:marqueeRepeatLimit="marquee_forever"
        android:scrollHorizontally="true"
        android:textColor="#ff4500"
        android:text="this is a very long piece of text that will move" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

在Java中:

        tv = (TextView) this.findViewById(R.id.tv);  
        tv.setSelected(true);  // Set focus to the textview
Run Code Online (Sandbox Code Playgroud)


Ovi*_*tcu 9

你应该用android:ellipsize="marquee".

编辑:你可以使用textView.setEllipsize(TextUtils.TruncateAt.MARQUEE);

  • 什么都没发生,对我来说结果与android:singleLine =“ True”相同 (2认同)

Dee*_*jan 6

<TextView
        android:id="@+id/YOURID"
        android:layout_width="15dp"
        android:layout_height="wrap_content"
        android:ellipsize="marquee"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:marqueeRepeatLimit="marquee_forever"
        android:scrollHorizontally="true"
        android:singleLine="true"
        />
Run Code Online (Sandbox Code Playgroud)

这将帮助它滚动直到它被聚焦