2014-12-03 90 views
0

我使用通用圖像加載器(UIL)在列表視圖中緩存和顯示圖像。Android /通用圖像加載器:不顯示圖像

我不能讓我想上面顯示圖像的描述圖像具有以下佈局列表視圖的項目

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
    > 

     <ImageView 
      android:id="@+id/image" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
     /> 

     <TextView 
      android:id="@+id/title" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
     /> 
</LinearLayout> 

顯示的圖像。圖像的寬度是設備的整個寬度,圖像的高度根據圖像的寬度自動縮放。

使用寬度和高度的「wrap_content」,我可以讓我的圖像顯示在其他不使用UIL的項目中。我不確定我在UIL的配置中做了什麼錯誤(我在他們的Github的例子中使用了相同的配置),但是圖像沒有用上面的佈局進行dsiplay。實際上他們顯示0高度。我可以讓他們顯示,如果我提供一個固定的高度,像

<ImageView 
     android:id="@+id/image" 
     android:layout_width="wrap_content" 
     android:layout_height="300dp" 
    /> 

請讓我知道如果你有任何解決方案。

回答

1

我設法在圖片視圖(onLoadingComplete)附加圖片視圖的寬度和高度後,根據位圖的尺寸手動更新圖片視圖的寬度和高度,圖片的尺寸也會在設備旋轉時重新計算以適應新屏幕的尺寸。

如果您有任何改進此解決方案的建議,如果您有任何其他解決方案,請發表評論。謝謝!

private static class AnimateFirstDisplayListener extends SimpleImageLoadingListener { 

    static final List<String> displayedImages = Collections.synchronizedList(new LinkedList<String>()); 

    @Override 
    public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { 
     if (loadedImage != null) { 
      ImageView imageView = (ImageView) view; 
      boolean firstDisplay = !displayedImages.contains(imageUri); 
      if (firstDisplay) { 
       FadeInBitmapDisplayer.animate(imageView, 500); 
       displayedImages.add(imageUri); 
      } 

      // Screen's width will be the width of the image. 
      float newWidth = Resources.getSystem().getDisplayMetrics().widthPixels; 

      // Get the width and the height of the image. 
      int oldWidth = imageView.getDrawable().getIntrinsicWidth(); 
      int oldHeight = imageView.getDrawable().getIntrinsicHeight(); 

      // Calculate the new height of the image based on the screen's width. 
      float newHeight = newWidth * oldHeight/oldWidth; 

      // Apply the new width and height values to ImageView. 
      imageView.getLayoutParams().width = (int) newWidth; 
      imageView.getLayoutParams().height = (int) newHeight; 
     } 
    } 
} 
0

我已經解決了這個問題,只是試圖做這樣的:

ImageLoader.getInstance().displayImage(mImageUrl, mImageView, PhotoUtils.avatarImageOptions,new SimpleImageLoadingListener() { 
     @Override 
     public void onLoadingStarted(String imageUri, View view) { 
      progressBar.setVisibility(View.VISIBLE); 
     } 

     @Override 
     public void onLoadingFailed(String imageUri, View view, FailReason failReason) { 
      String message = null; 
      switch (failReason.getType()) { 
       case IO_ERROR: 

        break; 
       case DECODING_ERROR: 

        break; 
       case NETWORK_DENIED: 

        break; 
       case OUT_OF_MEMORY: 

        break; 
       case UNKNOWN: 

        break; 
      } 
      Toast.makeText(getActivity(), message, Toast.LENGTH_SHORT).show(); 
      progressBar.setVisibility(View.GONE); 
     } 

     @Override 
     public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { 

      progressBar.setVisibility(View.GONE); 
      mAttacher.update(); 
     } 
    }); 
相關問題