无法将图像加载到Fragment com.nostra13.universalimageloader中的ImageView

时间:2014-08-24 08:58:20

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

我正在尝试使用来自nostra13的UniversalImageLoader在ImageView中加载图像,但它不会在片段中加载(图像为空白)。我看到了showImageOnLoading图标,但随后它消失了,尽管URL上存在图像,但图像仍未显示。我的实现如下:

package com.rayat.pricewiz.request;

import android.content.Context;
import android.widget.ImageView;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.rayat.pricewiz.R;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;


public class WebImageLoader {
DisplayImageOptions options;
ImageLoader imageLoader;

public WebImageLoader(Context context) {

    options = new DisplayImageOptions.Builder()
            .showImageOnLoading( context.getResources().getDrawable(R.drawable.ic_stub) )
            .showImageForEmptyUri(context.getResources().getDrawable(R.drawable.ic_empty))
            .showImageOnFail(context.getResources().getDrawable(R.drawable.ic_error))
            .cacheInMemory(true)
            .cacheOnDisk(true)
            .considerExifParams(true)
            .displayer(new RoundedBitmapDisplayer(20))
            .build();

    imageLoader = ImageLoader.getInstance();
    if (!imageLoader.isInited()) {
        imageLoader.init(ImageLoaderConfiguration.createDefault(context));
    }
}

public void displayImage(ImageView imageView,String imageURL) {
    imageLoader.displayImage(imageURL,imageView,options);
}
}

在片段中,我有这段代码:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    relativeLayout = (RelativeLayout)inflater.inflate(R.layout.premium_ad_fragment,container,false);
    ImageView imageView = (ImageView)relativeLayout.findViewById(R.id.imgPremiumAd);
    WebImageLoader imageLoader = new WebImageLoader(getActivity().getApplicationContext());
    imageLoader.displayImage(imageView,image_url);
    return relativeLayout;
}

请提出任何建议。

由于

1 个答案:

答案 0 :(得分:0)

好的,我发现,图片尺寸设置不正确,我在布局资源文件中将android:layout_width android:layout_heightImageView更改为match_parent现在看来