2013-04-30 144 views
4

我有一个使用Android universal image loader的图库。问题在于图像只是部分显示,如图像的一半,有时没有图像,但有时图像显示为整体。Android通用图像加载器部分显示图像

DisplayImageOptions options = new DisplayImageOptions.Builder() 
              .cacheInMemory() 
              .build(); 
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context) 
              .defaultDisplayImageOptions(options) 
              .threadPoolSize(1) 
              .threadPriority(Thread.MIN_PRIORITY + 3) 
              .denyCacheImageMultipleSizesInMemory() 
              .memoryCacheSize(2 * 1024 * 1024) 
              .enableLogging() 
              .build(); 

imageLoader = ImageLoader.getInstance(); 
imageLoader.init(config); 
imageLoader.handleSlowNetwork(true); 


subImage1 = (ImageView)findViewById(R.id.subImage1); 
subImage2 = (ImageView)findViewById(R.id.subImage2); 

imageLoader.displayImage("http://path/to/image1.webp", subImage1); 
imageLoader.displayImage("http://path/to/image2.webp", subImage2); 

布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context=".MyActivity" > 



<ImageView 
    android:id="@+id/subImage1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_centerVertical="true" /> 

<ImageView 
    android:id="@+id/subImage2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignTop="@+id/subImage1"/> 


</RelativeLayout> 

问题举例

enter image description here

可能是什么问题呢?

+0

您正在使用的图像视图的布局选项是什么? – 2013-04-30 08:14:54

+0

@Boris Strandjev我将我的布局添加到我的问题 – Krivers 2013-04-30 08:32:08

回答

1

最后我做了几个测试,结论是Android v4.0中的ImageView无法正常显示webp。我找到的唯一解决方案是在webView中显示webp图像,从而正确呈现此文件类型,例如如here

1

我有同样的问题

我相信,你正在寻找的解决方案,就在于此位这里

//Find the correct scale value. It should be the power of 2. 
final int REQUIRED_SIZE=70; 
int width_tmp=o.outWidth, height_tmp=o.outHeight; 
int scale=1; 
while(true){ 
if(width_tmp/2<REQUIRED_SIZE || height_tmp/2<REQUIRED_SIZE) 
    break; 
width_tmp/=2; 
height_tmp/=2; 
scale*=2; 
} 

这是从99号线在此线108:https://github.com/thest1/LazyList/blob/master/src/com/fedorvlasov/lazylist/ImageLoader.java

我正在链接这个,以便您可以检查源代码并与您的代码进行比较。

您需要在此更改此位:final int REQUIRED_SIZE = 70。请注意,这个数字需要2的幂。默认值为70时,您会看到小图像,并且在需要显示更大图像的应用程序中使用时,它们会看起来失真。玩这个,直到你对结果满意为止。

我个人使用final int REQUIRED_SIZE = 512的值,没有任何问题。

这应该对你有用。

+0

http://stackoverflow.com/questions/14621367/how-to-make-images-larger-in-height-in-lazy-list – 2013-04-30 09:03:57

+0

为什么选择投票? – 2013-04-30 10:18:56

+0

感谢您的建议,但我想这个问题是ImageView无法完全支持Android v4.0中的webp – Krivers 2013-04-30 15:52:25

相关问题