I'm doing the following simple animation in Android:
<?xml version="1.0" encoding="UTF-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:duration="2000"
android:interpolator="@android:anim/linear_interpolator"/>
I call the animation like this:
@Override
public void onWindowFocusChanged (boolean hasFocus) {
if (hasFocus) {
tvload.startAnimation(anim);
}
}
The animation starts immediately in pre-lollipop devices but in lollipop and Marshmallow it takes around 1 sec for it to start. This animation should start after intent.
Is there a way to make this animation start immediately instead of having the 1 second load time?
I would give the View#post() method a try. It will run the code you post next UI thread cycle which is usually as soon as the View is visible.
tvload.post(new Runnable() {
@Override
public void run() {
tvload.startAnimation(anim);
}
};
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.