由于GalleryView
已弃用,我们应该迁移到一些替代小部件,在我的情况下ViewFlipper
是最好的,但我遇到了几个问题,正如您在以下屏幕截图中看到的那样,我设计了一个轮ImageGallery
播GalleryView
:
一切都按我的预期ViewFlipper
工作,但我无法实现两件事:
1-ViewFlipper
始终显示一项;但是我需要一次显示三个项目(甚至更多)。
2-ViewFlipper
是不可触摸的小部件,这不是我想要的!
正如 FlávioFaria 在下一篇文章中提到ViewPager
的,这也是一个很好的案例,但我无法将放大动画传递给它!
我已经完成了一切ViewPager
,现在它工作得很好,但我错过了一个功能,那就是无限滚动!
添加了我的PagerAdapter
课程
public class CarouselAdapter extends PagerAdapter
{
private Context mContext;
private ImageLoader imageLoader;
private String[] bannerUri;
public CarouselAdapter (Context c, String[] bannerArray)
{
this.mContext = c;
this.bannerUri = bannerArray;
// Setup image loader
this.imageLoader = ImageLoader.getInstance();
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(c)
.threadPoolSize(2)
.memoryCache(new WeakMemoryCache())
.discCacheFileNameGenerator(new Md5FileNameGenerator())
.build();
this.imageLoader.init(config);
}
@Override
public Object instantiateItem(ViewGroup container, int position)
{
if (position >= bannerUri.length)
position %= bannerUri.length;
ImageView i = new ImageView(mContext);
displayImage(i, bannerUri[position]);
i.setScaleType(ScaleType.FIT_XY);
container.addView(i);
return i;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object)
{
container.removeView((View)object);
}
@Override
public int getCount()
{
return Integer.MAX_VALUE;
}
@Override
public boolean isViewFromObject(View view, Object object)
{
return (view == object);
}
private void displayImage(final ImageView mImage, String ImageUri)
{
DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.border)
.showImageForEmptyUri(R.drawable.border)
.imageScaleType(ImageScaleType.EXACTLY)
.bitmapConfig(Bitmap.Config.RGB_565)
.resetViewBeforeLoading()
.cacheOnDisc()
.displayer(new FadeInBitmapDisplayer(740))
.build();
imageLoader.loadImage(ImageUri, defaultOptions, new SimpleImageLoadingListener()
{
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage)
{
mImage.setImageDrawable(new BitmapDrawable(mContext.getResources()
, getDesiredBitmap(loadedImage, 12)));
}
});
}
private Bitmap getDesiredBitmap(Bitmap originalImage, int roundValue)
{
// Create required bitmaps
Bitmap shadowBitmap = BitmapFactory.decodeResource(mContext.getResources()
, R.drawable.samsungapps_thumb_shadow);
Bitmap outputBitmap = Bitmap.createBitmap(originalImage.getWidth()
, originalImage.getHeight() + 80, Bitmap.Config.ARGB_8888);
// Create canvas and pass bitmap to it
Canvas mCanvas = new Canvas(outputBitmap);
// And finally draw the shaodw
mCanvas.drawBitmap(Bitmap.createScaledBitmap(shadowBitmap, originalImage.getWidth()
, (int)(shadowBitmap.getHeight() / 2.3), false), 0, originalImage.getHeight(), null);
mCanvas.drawBitmap(originalImage, 0, 0, null);
return outputBitmap;
}
}
关于如何完成这两件事的任何想法?