Android textview animation infinite repetition does not work
•
Android
I'm trying to animate textview infinitely. I wrote sequence.xml, which defines the animation effects as follows:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:interpolator="@android:anim/linear_interpolator" >
<!-- Move -->
<translate
android:duration="800"
android:fillAfter="true"
android:fromXDelta="0%p"
android:startOffset="300"
android:toXDelta="2%p" />
<translate
android:duration="800"
android:fillAfter="true"
android:fromXDelta="0%p"
android:startOffset="1900"
android:toXDelta="-2%p" />
</set>
The activity code that assigns this animation to textview is as follows:
TextView tv = new TextView(this);
tv.setText(customObject.getText());
Animation animSequential;
animSequential = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.sequential_horizontal);
animSequential.setRepeatMode(Animation.RESTART);
animSequential.setRepeatCount(Animation.INFINITE);
tv.startAnimation(animSequential);
But this does not repeat the animation, but stops at the end of the first iteration. If I make a mistake, please let me know
resolvent:
Try it in XML code. Java code doesn't work properly, so I solved this problem well. Just apply this code in your code:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<rotate
android:fromdegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:todegrees="360"
android:duration="1000"
android:repeatCount="infinite"
android:repeatMode="restart"/>
</set>
Add the last two lines of < rotate >. In your code. In your case, < translate > in the two components and delete the equivalent java code:
animation.setRepeatMode(Animation.INFINITE);
animation.setRepeatCount(Animation.INFINITE);
If someone serves, this code will cause the object to rotate itself indefinitely
Good luck!!
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码