这是我的适配器的getVIEw代码:
public VIEw getVIEw(int position,VIEw vIEw,VIEwGroup parent) { RoundedImageVIEw photo = (RoundedImageVIEw) vIEw; if (photo == null) { photo = (RoundedImageVIEw) inflater.inflate(R.layout.row_gallery_latest_issue_item,parent,false); } try { System.out.println("Test is good"); ImageLoaderHelper.configureCacheableImage(mContext,photo,latestBook.get(position).getimageUrl(),R.drawable.avatar_issue,null); } catch (NullPointerException e) { photo.setimageResource(R.drawable.avatar_issue); e.printstacktrace(); } return createReflectedImages(photo);}
它与UniversalimageLoader完全相同Sample预计我有一个TryCatche和CreateReflectedImage(它使我们的ImageVIEw反射)
,还有一件我的ImageLoaderHelper:
public class ImageLoaderHelper {public static voID configureCacheableImage(Context context,ImageVIEw imageVIEw,String imageUrl,Integer defaultimageResourceID,ImageLoadingListener imageLoadingListener) { ImageLoader imageLoader = ImageLoader.getInstance(); displayImageOptions.Builder builder = new displayImageOptions.Builder(); builder.displayer( new SimpleBitmapdisplayer()) .cacheOndisc(true) .cacheInMemory(true) .resetVIEwBeforeLoading(true) .imageScaleType(ImageScaleType.IN_SAMPLE_INT) .bitmapConfig(Bitmap.Config.RGB_565); if (defaultimageResourceID != null) builder.showImageOnFail(defaultimageResourceID).showImageForEmptyUri(defaultimageResourceID).showStubImage(defaultimageResourceID); if (!imageLoader.isInited()) imageLoader.init(ImageLoaderConfiguration.createDefault(context)); imageLoader.displayImage(imageUrl,imageVIEw,builder.build(),imageLoadingListener);}
}
更新:
经过一天的调试后,我找到了一条线索问题出在我的适配器上但是我不知道如何解决它!
这是CreateReflectedImages()的代码:
public ImageVIEw createReflectedImages(RoundedImageVIEw image) { RoundedDrawable drawable = (RoundedDrawable) image.getDrawable(); Bitmap originalimage = drawable.toBitmap(); int wIDth = originalimage.getWIDth(); int height = originalimage.getHeight(); Matrix matrix = new Matrix(); matrix.preScale(1,-1); Bitmap reflectionImage = Bitmap.createBitmap(originalimage,height / 2,wIDth,matrix,false); Bitmap bitmapWithreflection = Bitmap.createBitmap(wIDth,(height + height / 2),Config.ARGB_8888); Canvas canvas = new Canvas(bitmapWithreflection); canvas.drawBitmap(originalimage,null); canvas.drawBitmap(reflectionImage,height,null); Paint paint = new Paint(); linearGradIEnt shader = new linearGradIEnt(0,bitmapWithreflection.getHeight(),0x70ffffff,0x00ffffff,TileMode.CLAMP); paint.setShader(shader); paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN)); canvas.drawRect(0,paint); RoundedImageVIEw imageVIEw = new RoundedImageVIEw(mContext); imageVIEw.setimageBitmap(bitmapWithreflection); imageVIEw.setLayoutParams(new Imagegallery3D.LayoutParams(GeneralHelper.dp(180),GeneralHelper.dp(240)));//wIDth and height of Image return imageVIEw;}解决方法 问题是你有2个独立的imagevIEw实例浮动. 1在getVIEw中创建,第二个在createReflectedImage中创建.所以基本上,当图像完成下载时,新的图像视图已经替换它,并且下载的图像被加载到不再可见(或甚至可能存在)的图像中.它第二次正确加载(在屏幕外滚动后)的原因是延迟要低得多,因为它是从内存加载而不是从网上或任何地方加载的,所以当RoundedDrawable drawable =(RoundedDrawable)image.getDrawable();它实际上有你想要的图像,而不仅仅是占位符!
public VIEw getVIEw(int position,VIEwGroup parent) { RoundedImageVIEw photo = (RoundedImageVIEw) vIEw; ... /* *Passing first instance of photo into ImageLoaderHelper */ ImageLoaderHelper.configureCacheableImage(mContext,null); ... // //Returns the new instance of RoundedImageVIEw that ImageLoader is not aware of to the adapter // return createReflectedImages(photo);}public ImageVIEw createReflectedImages(RoundedImageVIEw image) { ... RoundedImageVIEw imageVIEw = new RoundedImageVIEw(mContext); imageVIEw.setimageBitmap(bitmapWithreflection); imageVIEw.setLayoutParams(new Imagegallery3D.LayoutParams(GeneralHelper.dp(180),GeneralHelper.dp(240)));//wIDth and height of Image //Returning a new instance of imageVIEw return imageVIEw;}
而不是在createReflectedImages中返回imageVIEw,而是返回“image”.然后实现一个回调,传递给ImageLoaderHelper,在成功加载图像后调用createReflectedImages来应用效果.
总结以上是内存溢出为你收集整理的android – 结合CoverFlow和通用图像加载器全部内容,希望文章能够帮你解决android – 结合CoverFlow和通用图像加载器所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)