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>

问题示例

在此处输入图像描述

可能是什么问题呢?

4

2 回答 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 的值没有任何问题。

这应该为您解决问题。

于 2013-04-30T09:03:17.023 回答
1

最后我做了几个测试,得出的结论是Android v4.0中的ImageView不能正常显示webp。我发现的唯一解决方案是在 webView 中显示 webp 图像,它可以正确呈现这种文件类型,例如这里

于 2013-04-30T15:49:47.557 回答