开发者社区> 问答> 正文

升级Android Studio后,Android ValueAnimator不会协调一致地进行动画

我已经开始开发一个android应用程序,该应用程序应该显示淡出的文本以及一个圆形动画,并且在我升级Android Studio和所有相关组件之前,它一直很好地工作。现在开始,然后过一会儿停止。

活动代码:

package authenticator.cloudy.sh;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ArgbEvaluator;
import android.animation.ValueAnimator;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TextView;

public class AuthCodeDisplayActivity extends AppCompatActivity
{
    private static final int TIMER_LENGTH = 60;

    private String login_session = "";
    private TimerView mTimerView;
    private TextView code = null;

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.main_menu, menu);
        return true;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_auth_code_display);

        mTimerView = findViewById(R.id.tvIndicator);

        code = findViewById(R.id.tvCode);
        login_session = getIntent().getStringExtra("session_id");

        String authcode = getAuthCode(login_session);
        code.setText(authcode);

        int colorFrom = getResources().getColor(R.color.green);
        int colorTo = getResources().getColor(R.color.lightGray);
        final ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
        colorAnimation.setRepeatCount(0);
        colorAnimation.setRepeatMode(ValueAnimator.RESTART);
        colorAnimation.setDuration(60000); // milliseconds. Wait a full minute

        colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animator) {
                code.setTextColor((int) animator.getAnimatedValue());
            }
        });

        colorAnimation.addListener(new AnimatorListenerAdapter()
        {
            @Override
            public void onAnimationEnd(Animator animation)
            {
                String authcode = getAuthCode(login_session);
                code.setText(authcode);
                colorAnimation.cancel();
                colorAnimation.start();
                mTimerView.stop();
                mTimerView.start(TIMER_LENGTH);
            }
        });

        mTimerView.start(TIMER_LENGTH);
        colorAnimation.start();
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle item selection
        switch (item.getItemId()) {
            case R.id.action_logout:
                Intent it = new Intent(this, LoginActivity.class);
                startActivity(it);
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }

    public native String getAuthCode(String login_session);

}

动画停在随机无关的位置...

屏幕截图

在日志中,我看到:

2019-11-27 11:01:25.324 9985-9985/authenticator.cloudy.sh I/Choreographer: Skipped 1227 frames!  The application may be doing too much work on its main thread.
2019-11-27 11:01:25.352 9985-10076/authenticator.cloudy.sh I/OpenGLRenderer: Davey! duration=20481ms; Flags=0, IntendedVsync=4130536114668, Vsync=4150986113850, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=4150990713259, AnimationStart=4150991097639, PerformTraversalsStart=4150995257469, DrawStart=4150998067709, SyncQueued=4151003352039, SyncStart=4151004336259, IssueDrawCommandsStart=4151004700059, SwapBuffers=4151007019369, FrameCompleted=4151018470959, DequeueBufferDuration=378000, QueueBufferDuration=558000, 
2019-11-27 11:03:04.805 9985-9985/authenticator.cloudy.sh W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@228ab5f
2019-11-27 11:03:33.154 9985-10076/authenticator.cloudy.sh W/OpenGLRenderer: dequeueBuffer failed, error = -110; switching to fallback
2019-11-27 11:03:33.173 9985-10076/authenticator.cloudy.sh W/Gralloc3: allocator 3.x is not supported
2019-11-27 11:03:33.179 9985-10076/authenticator.cloudy.sh W/OpenGLRenderer: reserveNext failed, error = -2147483648 (Unknown error -2147483648)
2019-11-27 11:03:33.182 9985-9985/authenticator.cloudy.sh I/Choreographer: Skipped 32 frames!  The application may be doing too much work on its main thread.
2019-11-27 11:09:03.647 9985-10003/authenticator.cloudy.sh I/cator.cloudy.s: Background young concurrent copying GC freed 51926(1207KB) AllocSpace objects, 0(0B) LOS objects, 42% free, 1807KB/3120KB, paused 1.168ms total 498.355ms
2019-11-27 11:11:46.313 9985-9985/authenticator.cloudy.sh I/Choreographer: Skipped 72 frames!  The application may be doing too much work on its main thread.
2019-11-27 11:17:08.115 9985-10072/? W/cator.cloudy.s: Suspending all threads took: 12.359ms
2019-11-27 11:17:12.673 9985-9985/? I/Choreographer: Skipped 269 frames!  The application may be doing too much work on its main thread.
2019-11-27 11:17:13.918 9985-10673/authenticator.cloudy.sh W/cator.cloudy.s: Something went wrong with handling the ddm chunk.
2019-11-27 11:19:22.681 9985-10003/authenticator.cloudy.sh I/cator.cloudy.s: Background concurrent copying GC freed 73671(1245KB) AllocSpace objects, 0(0B) LOS objects, 49% free, 1778KB/3556KB, paused 350us total 435.709ms

由于我处于Android开发的初级阶段(这或多或少是我的学习项目),所以我真的不知道下一步要做什么,所以请您在这里张贴我拥有的所有代码(TimerView大致相同于:https : //github.com/puercos/puercos-android/blob/master/app/src/main/java/com/puercos/puercos/components/timerView/TimerView.java),有人对正在发生的事情有一个想法,可以给出一些指示。

展开
收起
垚tutu 2019-11-28 19:27:29 4344 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
58同城Android客户端Walle框架演进与实践之路 立即下载
Android组件化实现 立即下载
蚂蚁聚宝Android秒级编译——Freeline 立即下载