如何在Universal Image Loader中设置存根图像的比例类型?

时间:2015-08-28 19:19:48

标签: android imageview progress-bar universal-image-loader

我有动画可绘制的进度条并将其设置为UniversalImageLoader配置。问题是当我在ImageView中有缩放类型时,进度存根图像也会缩放。

R.drawable.dancing_ellipsis:
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:duration="33" android:drawable="@drawable/ellipsis_20" />
  <item android:duration="33" android:drawable="@drawable/ellipsis_21" />
  <item android:duration="33" android:drawable="@drawable/ellipsis_22" />
  <item android:duration="33" android:drawable="@drawable/ellipsis_23" />
  <item android:duration="500" android:drawable="@drawable/ellipsis_39" />
</animation-list>
final DisplayImageOptions options = new DisplayImageOptions.Builder()
            .resetViewBeforeLoading(true)
            .postProcessor(null)
            .imageScaleType(ImageScaleType.EXACTLY)
            .cacheInMemory(true)
            .cacheOnDisk(true)
            .displayer(new FadeInBitmapDisplayer(150))     
            .showImageOnFail(R.drawable.image_catalog_error)    
            .showImageOnLoading(R.drawable.dancing_ellipsis)
    ...
    imageLoader.displayImage(url, imageView);
<ImageView
    android:id="@+id/imageView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:scaleType="fitCenter"
    android:layout_gravity="center"
    android:background="@null"/>

1 个答案:

答案 0 :(得分:0)

此结果由于存根图像和网络图像使用相同的ImageViewscaleType是适用于图像源的ImageView属性。

如果您想使用不同的scaleType,有两种方式,一种方法是使用两种ImageView,另一种方法是更新scaleType

WAY1:

public class PreImageLoadingListener implements ImageLoadingListener {
    ImageView preImage

    public PreImageLoadingListener(ImageView preImage) {
        this.preImage = preImage;
    }

    @Override
    public void onLoadingStarted(String imageUri, View view) {
        preImage.setVisibility(View.VISIBLE);
    }

    @Override
    public void onLoadingFailed(String imageUri, View view, FailReason failReason) {

    }

    @Override
    public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
        preImage.setVisibility(View.GONE);

    }

    @Override
    public void onLoadingCancelled(String imageUri, View view) {

    }
}

Way2:

public class PreImageLoadingListener implements ImageLoadingListener {
    ImageView.ScaleType preScaleType;
    ImageView.ScaleType scaleType;

    public PreImageLoadingListener(ImageView.ScaleType preScaleType, ImageView.ScaleType scaleType) {
        this.preScaleType = preScaleType;
        this.scaleType = scaleType;
    }

    @Override
    public void onLoadingStarted(String imageUri, View view) {
        ImageView imageView = (ImageView) view;
        imageView.setScaleType(preScaleType);
    }

    @Override
    public void onLoadingFailed(String imageUri, View view, FailReason failReason) {

    }

    @Override
    public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
        ImageView imageView = (ImageView) view;
        imageView.setScaleType(scaleType);
    }

    @Override
    public void onLoadingCancelled(String imageUri, View view) {

    }
}