简体   繁体   English

动画android立即启动

[英]Animation android start immediately

I'm doing the following simple animation in Android: 我正在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. 动画在棒棒糖之前的设备中立即开始,但是在棒棒糖和棉花糖中大约需要1秒钟才能开始。 This animation should start after intent. 该动画应在意图之后开始。

Is there a way to make this animation start immediately instead of having the 1 second load time? 有没有一种方法可以使此动画立即开始而不是具有1秒的加载时间?

I would give the View#post() method a try. 我会尝试View#post()方法。 It will run the code you post next UI thread cycle which is usually as soon as the View is visible. 它将运行您在下一个UI线程周期中发布的代码,该周期通常是在显示视图后立即进行。

tvload.post(new Runnable() {
  @Override
  public void run() {
     tvload.startAnimation(anim);
  }
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM