我正在尝试使用Android和图像识别API创建在线扫描程序。我正在尝试使用动画触发器创建漂亮的布局。它看起来像like this。
我目前所有的东西都运行良好,只有一个例外:动画。这个蓝色触发器的动画是可以的,但是当AsyncTask将照片发布到API时,激光的动画会暂停一段时间。我该怎么做才能防止这种行为?
这是我的动画代码:
final View laser = findViewById(R.id.laser);
laser.setDrawingCacheEnabled(true);
final View trigger = findViewById(R.id.trigger);
Animation fadeAnimation = new AlphaAnimation(1.0f, 0.5f);
fadeAnimation.setRepeatCount(Animation.INFINITE);
fadeAnimation.setRepeatMode(Animation.REVERSE);
fadeAnimation.setDuration(3000);
trigger.setDrawingCacheEnabled(true);
trigger.startAnimation(fadeAnimation);
trigger.post(new Runnable() {
@Override
public void run() {
final Animation translateDownAnimation = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.25f,
Animation.RELATIVE_TO_PARENT, 0.75f);
final Animation translateUpAnimation = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.75f,
Animation.RELATIVE_TO_PARENT, 0.25f);
translateDownAnimation.setDuration(ANIMATION_TIME);
translateDownAnimation.setRepeatCount(0);
translateDownAnimation.setRepeatMode(Animation.RESTART);
translateUpAnimation.setDuration(ANIMATION_TIME);
translateUpAnimation.setRepeatCount(0);
translateUpAnimation.setRepeatMode(Animation.RESTART);
translateDownAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
translateUpAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
translateDownAnimation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
laser.setBackgroundResource(R.drawable.scanner_line_down);
}
@Override
public void onAnimationRepeat(Animation animation) {}
@Override
public void onAnimationEnd(Animation animation) {
laser.startAnimation(translateUpAnimation);
}
});
translateUpAnimation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
laser.setBackgroundResource(R.drawable.scanner_line_up);
}
@Override
public void onAnimationRepeat(Animation animation) {}
@Override
public void onAnimationEnd(Animation animation) {
laser.startAnimation(translateDownAnimation);
}
});
laser.setVisibility(View.VISIBLE);
laser.startAnimation(translateDownAnimation);
}
});
如果它有用,我可以准备正确的.apk文件。