2015-05-30 12 views
8

Używam fancyCoverFlow i universalImageLoader do wyświetlania mojej niestandardowej galerii 3D: D coś jak poniżej obrazek. Moim problemem jest to, że nie wyświetla obrazów po pobraniu, chyba że przesuję między zdjęciami galerii, a obraz ukrywa się przed ekranem, a gdy pojawi się następnym razem, gdy pokazuje obraz, ale w Sample of UniversalImageLoader pobrany obraz jest wyświetlany zaraz po pobraniu.Łączenie CoverFlow i Universal Image Loader

Oto mój kod getView dla adaptera:

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

jest dokładnie taka sama jak UniversalImageLoader Sample oczekiwać mam TryCatche i CreateReflectedImage (co czyni naszą ImageView odblaskowe)

, i jeszcze jedno moje ImageLoaderHelper jest:

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:

Po dniu debugowanie znalazłem wskazówkę Problem jest z Mojego adapterem, ale nie wiem jak go rozwiązać!

Oto kod 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; 
} 
+0

Lepiej przenieś metodę DisplayImageOptions.Builder z metody i zainicjuj ją gdzie indziej, a następnie buduj dla każdego nowego tworzonego wiersza. Można również ustawić, aby ImageLoadingListener sprawdzał, czy obraz został pobrany. – razzledazzle

+0

@razzledazzle Dziękuję za twoją sugestię Naprawię DisplayImageOptions.Builder, sprawdzanie nie rozwiąże mojego problemu, ponieważ kiedy zamknę aplikację (zniszczę działanie) i ponownie uruchom galerię działań Nie pokazano w pamięci podręcznej Obrazy zostały pobrane. – Amir

Odpowiedz

1

Problemem jest to, że masz 2 osobne instancje ImageView pływających wokół. 1 jest tworzony w getView, a drugi jest tworzony w createReflectedImage. Zasadniczo, gdy pobieranie kończy się, nowy obraz już go zastąpił, a pobrany obraz został załadowany do tego, który nie jest już widoczny (lub nawet istnieje). Powodem, dla którego ładuje się poprawnie po raz drugi (po przewinięciu poza ekranem) jest to, że opóźnienie jest znacznie mniejsze, ponieważ jest ładowane z pamięci, nie z sieci lub gdziekolwiek, więc gdy RoundedDrawable drawable = (RoundedDrawable) image.getDrawable(); faktycznie ma obraz, który chcesz, a nie tylko symbol zastępczy!

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

Zamiast zwracania obrazu Wyświetl w createReflectedImages, zwróć "obraz". Następnie zaimplementuj wywołanie zwrotne przekazywane do ImageLoaderHelper, które wywołuje createReflectedImages po pomyślnym załadowaniu obrazu w celu zastosowania efektu.

Powiązane problemy