可以检测 TextView 的选取框动画何时完成? [英] Possible to detect when a TextView's marquee animation has completed?

查看:21
本文介绍了可以检测 TextView 的选取框动画何时完成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我将 TextView 的 ellipsize 值设置为 "marquee" 并将 marqueeRepeatLimit 值设置为 "1"例如(为了在 TextView 上滚动长文本一次),有没有办法检测选框动画何时完成?

If I set a TextView's ellipsize value to "marquee" and the marqueeRepeatLimit value to "1" for example (in order to roll a long text across a TextView once), is there any way to detect when the marquee animation has completed?

(问题是,我有一个字符串队列正在动态添加,我想一次取出并显示其中一个字符串.字符串可能比 TextView 的宽度长,所以我想在我展示下一个之前滚动它.)

(Thing is, I have a queue of Strings which is being added to dynamically and I want to pull out and show one of these Strings at a time. A String can be longer than the width of the TextView so I want to roll it across before I show the next one.)

如果无法通过使用 TextView 的选取框属性来做到这一点,那么任何人都知道如何将动画添加到模拟选取框动画的 TextView 中?

If it's not possible to do this by using TextView's marquee properties, anyone know how can I add an Animation to a TextView which simulates a marquee animation?

推荐答案

据我所知,无法检测到字幕动画何时完成,即使我在 TextView 上使用平移动画复制了字幕动画,根据 TextView 中的文本将动画的持续时间设置为正确的时间长度并不简单.所以!我现在正在做的是使用 TextSwitcher,如下所示...

As far as I can tell, it's not possible to detect when a marquee animation completes and even if I replicated the marquee animation using a translate animation on the TextView, it wouldn't be straightforward to set the duration of the animation the right length of time according to the text in the TextView. So! What I'm doing now instead is using a TextSwitcher as follows...

<TextSwitcher
    android:id="@+id/myTextSwitcher"
    ...
    android:inAnimation="@anim/fade_in_slow"
    android:outAnimation="@anim/fade_out_slow" >
<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:singleLine="true"
    android:ellipsize="marquee"
    android:marqueeRepeatLimit="marquee_forever"
    android:focusable="true"
    android:focusableInTouchMode="true" />
<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:singleLine="true"
    android:ellipsize="marquee"
    android:marqueeRepeatLimit="marquee_forever"
    android:focusable="true"
    android:focusableInTouchMode="true" />

... 并经常使用 Timer 调用 myTextSwitcher.setText("text to show next") 方法.不理想,但我能想到的最好的!

... and calling the myTextSwitcher.setText("text to show next") method every so often using a Timer. Not ideal but the best I could come up with!

这篇关于可以检测 TextView 的选取框动画何时完成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆