这就是我做到的.首先,我使用了很多
Android Displaying Bitmaps in Your UI tutorial的代码.
然后,我添加了以下调整:
在包含ViewPager的活动的OnCreate中:
mPager.setOnPageChangeListener(new OnPageChangeListener() {
@Override
public void onPageSelected(int arg0) {
PhotoViewerFragment currentFragment = mAdapter
.getFragment(arg0);
if (currentFragment != null) {
if (mRunningSlideshow) {
currentFragment.addImageTransition();
}
}
}
@Override
public void onPageScrollStateChanged(int arg0) {
// TODO Auto-generated method stub
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
// TODO Auto-generated method stub
}
});
在包含ViewPager的活动中运行幻灯片的Runnable:
private Runnable runSlideshow = new Runnable() {
public void run() {
// Second parameter of false turns ViewPager scroll animation off
mPager.setCurrentItem(mPager.getCurrentItem() + 1, false);
mSlideshowHandler.postDelayed(runSlideshow,
SLIDESHOW_IMAGE_DURATION);
}
};
在显示图像的片段中:
private static final int FADE_IN_TIME = 200;
/**
* Adds fade-in transition when in slideshow mode. Called from PhotoViewerActivity.
*/
public void addImageTransition() {
// Transition drawable with a transparent drawable and the final bitmap
final TransitionDrawable td = new TransitionDrawable(new Drawable[] {
new ColorDrawable(android.R.color.transparent),
mImageView.getDrawable() });
mImageView.setImageDrawable(td);
td.startTransition(FADE_IN_TIME);
}