2014-12-03 92 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(); 
     } 
    }); 
相关问题