Possible to detect when a TextView's marquee animation has completed?

陌路散爱 提交于 2019-12-18 07:22:12

问题


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?

(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.)

Edit: 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?


回答1:


instead of marquee just try the simple animation on the text, there you can define in which style text should move, with what speed and direction.
You can set the result to show after the animation is complete by using "setFillAfter()" method (showing the default text in your case).




回答2:


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

... 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!



来源:https://stackoverflow.com/questions/9006252/possible-to-detect-when-a-textviews-marquee-animation-has-completed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!