【发布时间】:2017-01-31 01:26:50
【问题描述】:
我正在尝试在我的测试项目中使用通用图像加载器 (UIL),并且我认为当图像的高度大于其宽度时我无法加载图像。 UIL 加载到我的图像视图的图像太小,即使图像实际上很大。因此,当我拉伸图像视图以匹配其父视图时,图像似乎严重模糊且质量低下。
但是当它们的高度小于或等于它们的宽度时,UIL 会正确加载我的图像。
这是我的java代码:
DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
.cacheOnDisk(true)
.imageScaleType(ImageScaleType.NONE)
.bitmapConfig(Bitmap.Config.ARGB_8888)
.build();
File cacheDir = StorageUtils.getCacheDirectory(getApplicationContext());
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
.defaultDisplayImageOptions(defaultOptions)
.threadPoolSize(1)
.diskCache(new UnlimitedDiskCache(cacheDir))
.diskCacheExtraOptions(480, 320, null)
.build();
ImageLoader imageLoader = ImageLoader.getInstance();
imageLoader.init(config);
String imageURL;
ImageView imageView1 = (ImageView)findViewById(R.id.imageview1);
imageURL = "http://www.up.edu.ph/wp-content/uploads/2017/01/twsc-40th-posters-WEB-01.png";
imageLoader.displayImage(imageURL, imageView1);
ImageView imageView2 = (ImageView)findViewById(R.id.imageview2);
imageURL = "http://www.up.edu.ph/wp-content/uploads/2017/01/UPD-Chancy-Selection1.png";
imageLoader.displayImage(imageURL, imageView2);
这是我的 xml 代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="ph.edu.up.e.universalimageloadersample.MainActivity"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/imageview1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="centerCrop" />
<ImageView
android:id="@+id/imageview2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="centerCrop" />
</LinearLayout>
</ScrollView>
</LinearLayout>
这是 UIL 加载图像时的样子:
请不要推荐任何其他图片加载器。除此之外,任何帮助将不胜感激。谢谢!
【问题讨论】:
-
使用Glide
-
感谢您的建议
标签: java android xml imageview universal-image-loader