【问题标题】:Unable to load image to ImageView in Fragment com.nostra13.universalimageloader无法将图像加载到 Fragment com.nostra13.universalimageloader 中的 ImageView
【发布时间】:2014-08-24 08:58:20
【问题描述】:

我正在尝试使用来自 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;
}

请给点建议。

谢谢

【问题讨论】:

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


    【解决方案1】:

    好的,我想通了,图像大小设置不正确,我在布局资源文件中将ImageViewandroid:layout_widthandroid:layout_height 更改为match_parent,现在它出现了

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-09
      • 1970-01-01
      • 2017-10-21
      • 1970-01-01
      相关资源
      最近更新 更多