【问题标题】:Android universal image loader showing images partiallyAndroid 通用图像加载器部分显示图像
【发布时间】:2013-04-30 08:02:43
【问题描述】:

我有一个使用Android universal image loader 的画廊。问题是图像只是部分显示,比如图像的一半,有时没有图像,但有时图像是完整的。

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>

问题示例

可能是什么问题?

【问题讨论】:

  • 您正在使用的图像视图的布局选项是什么?
  • @Boris Strandjev 我将布局添加到我的问题中

标签: java android image android-imageview universal-image-loader


【解决方案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 的值没有任何问题。

这应该对你有用。

【讨论】:

【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 2013-07-14
    • 1970-01-01
    • 2015-03-22
    • 2021-11-12
    • 2017-04-07
    • 1970-01-01
    • 2017-09-24
    • 2013-03-30
    • 2013-05-20
    相关资源
    最近更新 更多