如何使Google Play在文本过长时像TextView动画一样显示?

4
当某个标题在Google Play上的名称过长时,他们会对这个TextView应用动画效果,当名称从TextView的一端消失时,会从另一端进入,停留一秒钟在标题文本的开头,然后进行下一轮。请问有人知道如何实现这种效果吗?

你是在说“文本跑马灯”还是多行显示? - gian1200
2个回答

5
这是我的解决方法,你必须实际请求焦点才能使跑马灯动画正常工作:
  <TextView
        android:id="@+id/tvAddress"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/tvName"
        android:layout_toLeftOf="@+id/ivLogo"
        android:text=""
        android:textColor="@color/cups_white"
        android:textSize="18sp" 
        android:ellipsize="marquee"
        android:singleLine="true"
        android:marqueeRepeatLimit ="marquee_forever"
        android:scrollHorizontally="true"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:duplicateParentState="true">
        <requestFocus 
          android:focusable="true" 
          android:focusableInTouchMode="true"
          android:duplicateParentState="true" />
    </TextView>

1
在声明 TextView 的 xml 文件中,您可以使用以下属性:
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true"

使用singleline属性可以确保文本只显示在一行中。
要了解更多细节,请查看:http://developer.android.com/reference/android/widget/TextView.html

看起来答案是正确的,但出于某些原因它对我没有用,文本只以“..”结束,没有任何动画效果。 - Emil Adz
好的,请尝试添加以下内容:android:scrollHorizontally="true" - Manu Zi
1
让我成功的方法是在TextView上以程序方式调用“setSelected(true)”函数。 - amp

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接