Android通用图像加载器只显示部分图像

4

我有一个图库,使用的是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

可能存在什么问题?


你正在使用的图像视图有哪些布局选项? - Boris Strandjev
@Boris Strandjev 我已经将我的布局添加到了我的问题中。 - Krivers
2个回答

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的值,没有任何问题。
这应该可以解决您的问题。

https://dev59.com/gm3Xa4cB1Zd3GeqPj-QP - Qadir Hussain
谢谢您的建议,但我认为问题在于ImageView无法在Android v4.0中完全支持webp。 - Krivers

1
最后我进行了几次测试,结论是Android v4.0中的ImageView无法正确显示webp格式的图片。我发现唯一的解决方案是在webView中显示webp图片,这种方式可以正确渲染该文件类型,例如这里

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接