【发布时间】:2019-07-11 18:23:08
【问题描述】:
我尝试为片段中的文本视图设置动画以飞入 - 在那里停留几秒钟 - 飞出 - 重复。动画有效,但我不让它重复它。当动画结束时,AnimationListener 会触发 onAnimationEnd 事件。我试过setRepeatCount(Animation.INFINITE);
和setRepeatMode(Animation.RESTART/Animation.REVERSE);,但似乎没有任何效果。
在这里可以看到带有动画内容的 text_slider_animation.xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:fillEnabled="true"
android:interpolator="@android:anim/linear_interpolator">
<set
android:fillAfter="true"
android:fillEnabled="true"
android:startOffset="500"
android:duration="1000">
<translate
android:fromXDelta="-100%"
android:toXDelta="0%" />
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0" />
</set>
<set
android:fillAfter="true"
android:fillEnabled="true"
android:startOffset="6000"
android:duration="1000">
<translate
android:fromXDelta="0%"
android:toXDelta="100%" />
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.0" />
</set>
</set>
我尝试使用以下代码:
AnimationSet mAnimation = (AnimationSet) AnimationUtils.loadAnimation(getActivity(), R.anim.text_slider_animation);
mAnimation.setRepeatCount(Animation.INFINITE);
mAnimation.setRepeatMode(Animation.RESTART);
myTextView.startAnimation(mAnimation);
mAnimation.setAnimationListener(new Animation.AnimationListener() {
public void onAnimationStart(Animation animation) {}
public void onAnimationRepeat(Animation animation) {
Toast.makeText(getActivity(), "Repeat", Toast.LENGTH_SHORT).show();
// TODO: Replace text in TextView
}
public void onAnimationEnd(Animation animation) {
Toast.makeText(getActivity(), "Finish", Toast.LENGTH_SHORT).show();
}
});
有人可以帮助我为什么这不起作用吗?提前谢谢!
/////////////////////
编辑:我更正了 mAnimation.setRepeatCount(Animation.INFINITE); mAnimation.setRepeatMode(Animation.RESTART);
【问题讨论】:
-
我看到了这篇文章,但不幸的是无法解决我的问题
标签: java android xml android-layout animation