Combining CoverFlow and the universal image downloader

I use fancyCoverFlow and universalImageLoader to show my own 3D gallery: D is something like below. My problem is that it does not show the image when loading, if I do not scroll between the gallery pictures and that the image is hiding from the screen, and when it appears the next time the image is displayed. But in the UniversalImageLoader sample, the loaded image is displayed immediately after they are downloaded.

Here is my getView code for the adapter:

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); } 

it is exactly the same as UniversalImageLoader. Example: I have TryCatche and CreateReflectedImage (which make our ImageView Reflective)

and one more thing: 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); } 

}

enter image description here

UPDATE:

After a day of debugging, I found that the problem was with My Adapter. But I do not know how to solve it!

Here is the code for 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, 0, height / 2, width, height / 2, matrix, false); Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + height / 2), Config.ARGB_8888); Canvas canvas = new Canvas(bitmapWithReflection); canvas.drawBitmap(originalImage, 0, 0, null); canvas.drawBitmap(reflectionImage, 0, height, null); Paint paint = new Paint(); LinearGradient shader = new LinearGradient(0, height, 0, bitmapWithReflection.getHeight() , 0x70ffffff, 0x00ffffff, TileMode.CLAMP); paint.setShader(shader); paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN)); canvas.drawRect(0, height, width, bitmapWithReflection.getHeight() , 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; } 
+8
android image universal-image-loader gallery coverflow
source share
1 answer

The problem is that you have two separate instances of the image floating around. 1 is created in getView, and the second is created in createReflectedImage. Thus, when the image finishes loading, the new image already replaces it, and the downloaded image is loaded into one that is no longer visible (or perhaps even exists). The reason it loads correctly the second time (after scrolling the screen) is because the wait time is much lower since it loads from memory off-network or anywhere, so when RoundedDrawable drawable = (RoundedDrawable) image.getDrawable (); in fact, he has the image you want, not just a placeholder!

 public View getView(int position, View view, ViewGroup parent) { RoundedImageView photo = (RoundedImageView) view; ... /* *Passing first instance of photo into ImageLoaderHelper */ ImageLoaderHelper.configureCacheableImage(mContext, photo, latestBook.get(position).getImageUrl(), R.drawable.avatar_issue, 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; } 

Instead of returning the imageView to createReflectedImages, return the "image". Then do the callback you pass to ImageLoaderHelper, which calls createReflectedImages after the image has been successfully loaded to apply your effect.

+1
source share

All Articles