我有二十张图像,并且一个接一个地进行过渡。转换与定时器一起在以下循环中实现。
final Runnable mUpdateResults = new Runnable() {
public void run() {
AnimateandSlideShow();
}
};
final int delay = 2000;
final long period = 2000;
final Timer timer = new Timer();
final Handler mHandler = new Handler();
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
mHandler.post(mUpdateResults);
}
}, delay, period);
private void AnimateandSlideShow() {
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), IMAGE_IDS[currentimageindex%IMAGE_IDS.length]);
slidingimage = (ImageView)findViewById(R.id.mainImageView);
int imViewheight = 400;
int imViewwidth = 600;
Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, imViewwidth, imViewheight, true);
slidingimage.setImageBitmap(convertColorIntoBlackAndWhiteImage(scaledBitmap));
currentimageindex++;
slidingimage.startAnimation(fadeInAnimation);
slidingimage.startAnimation(fadeOutAnimation);
}
我喜欢做过渡淡入,显示 1000 毫秒,淡出。它被实现为
Animation fadeOutAnimation = new AlphaAnimation(1.0f, 0.0f);
Animation fadeInAnimation = new AlphaAnimation(0.0f, 1.0f);
fadeInAnimation.setDuration(2000);
fadeOutAnimation.setDuration(2000);
现在发生的只是淡入或淡出。只有其中之一。如何使图像先淡入,然后显示 1000 毫秒并淡出。