[英]Android - Display an image in ImageView for 10ms
我正在嘗試在ImageView中顯示圖片的時間很短,以免引起人們的注意。 我希望我可以顯示一張大約10ms ... 20ms ... 50ms的圖片
我嘗試了:
阿爾法動畫
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
我也嘗試過線程睡眠
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();
嘗試逐幀動畫,其中一幀包含要顯示的圖片,另一幀包含空白的透明圖片。 將相框的持續時間設置為所需的任意毫秒。 如果您在動畫列表的定義中設置了android:oneshot =“ true”,則運行動畫將使圖片閃爍一次。
http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.