Reputation: 251
I'm trying to display a picture in an ImageView for a very short time to people's eye reaction. I wish i could show a picture for about 10ms... 20ms... 50ms
I tryed with :
Alpha Animation
final Animation animation = new AlphaAnimation(0.0f, 1.0f);
animation.setDuration(1);
animation.setInterpolator(new LinearInterpolator());
animation.setRepeatCount(1);
animation.setRepeatMode(Animation.REVERSE);
Handlers postdelayed
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
i also tryed with 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));
The two first ones almost work, but the image is displayed for more than 10ms... i think it's most about 100ms
In the last case, the image is not displayed at all.I figured that in this case, the View is not refreshed as fast as i want.
How can display my picture for 10ms ?
SOLUTION :
based on the answer :
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();
Upvotes: 0
Views: 492
Reputation: 1530
Try a frame by frame animation with one frame consisting the picture to be displayed and other frame consisting of a blank transparent picture. Set duration for the picture frame to whatever ms of time your want. Running the animation will flash the picture once, provided you set android:oneshot="true" in animation list's definition.
http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html
Upvotes: 1