我正试图在很短的时间内在ImageView中显示一张图片,让人眼睛反应过来。 我希望我可以显示大约10ms ... 20ms ... 50ms的图片
我尝试过:
Alpha动画
final Animation animation = new AlphaAnimation(0.0f, 1.0f);
animation.setDuration(1);
animation.setInterpolator(new LinearInterpolator());
animation.setRepeatCount(1);
animation.setRepeatMode(Animation.REVERSE);
处理程序后延迟
Handler handler2 = new Handler();
handler2.postDelayed(new Runnable() {
@Override
public void run() {
mImageView.setVisibility(View.INVISIBLE);
System.out.println(System.currentTimeMillis());
mImageView.setImageDrawable(getResources().getDrawable(drawable.interogation));
}
}, 10); //10ms
我也试过Thread Sleep
mImageView.setVisibility(View.VISIBLE);
mImageView.setImageBitmap(loadedImage);
System.out.println(System.currentTimeMillis());
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(System.currentTimeMillis());
mImageView.setVisibility(View.INVISIBLE);
mImageView.setImageDrawable(getResources().getDrawable(drawable.interogation));
两个第一个几乎可以工作,但图像显示超过10毫秒...我认为它最多约100毫秒
在最后一种情况下,图像根本不显示。我想在这种情况下,视图不会像我想要的那样快速刷新。
如何在10ms内显示我的照片?
解决方案:
基于答案:
AnimationDrawable frameAnimation = new AnimationDrawable();
frameAnimation.addFrame(getResources().getDrawable(R.drawable.blank), 10);
frameAnimation.addFrame(new BitmapDrawable(getResources(), loadedImage),howLong);
frameAnimation.addFrame(getResources().getDrawable(R.drawable.interogation), 10);
frameAnimation.setOneShot(true);
mImageView.setImageDrawable(frameAnimation);
frameAnimation.start();
答案 0 :(得分:1)
尝试逐帧动画,其中一帧包含要显示的图片,另一帧包含空白透明图片。将相框的持续时间设置为您想要的任何ms时间。如果在动画列表的定义中设置了android:oneshot =“true”,则运行动画会使图片闪烁一次。
http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html