Frage

I am trying to set background for the image view. But not got luck to set background using universal image loader.

I am using following code.

DisplayImageOptions options = new DisplayImageOptions.Builder()
                                    .showStubImage(R.drawable.mo_no_image)
                                    .showImageForEmptyUri(R.drawable.mo_no_image)
                                    .cacheInMemory().cacheOnDisc()
                                    .displayer(new RoundedBitmapDisplayer(0))
                                    .imageScaleType(ImageScaleType.EXACTLY).build();
ImageLoader.getInstance().displayImage("url_to_load_image", imgView, options);

By using above code I am able to set image resource which check aspect ratio and using that modifying image size. I want to set downloaded image to the background of image view.

War es hilfreich?

Lösung

I can recommend a different way that works like a charm: Android Query.

You can download that jar file from http://code.google.com/p/android-query/downloads/list

AQuery androidAQuery=new AQuery(this);

As an example:

androidAQuery.id(YOUR IMAGEVIEW).image(YOUR IMAGE TO LOAD, true, true, getDeviceWidth(), ANY DEFAULT IMAGE YOU WANT TO SHOW);

It's very fast and accurate, and using this you can find many more features like Animation when loading; getting a bitmap, if needed; etc.

In your case you need to fetch Bitmap, so for it, use below code

androidAQuery.ajax(YOUR IMAGE URL,Bitmap.class,0,new AjaxCallback<Bitmap>(){
                        @Override
                        public void callback(String url, Bitmap object, AjaxStatus status) {
                            super.callback(url, object, status);

                            //You will get Bitmap from object.
                        }

});

Use this bitmap to set your background resource of ImageView using method.

Andere Tipps

Universal Image Loader also provide to use the Background functionality.Please check the below coed for it:-

Here Uri is the path of the folder image OR the url of the image.

imageLoader.loadImage(YOUR_URL, new SimpleImageLoadingListener() {
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
   super.onLoadingComplete(imageUri, view, loadedImage);
   layout.setBackgroundDrawable(new BitmapDrawable(loadedImage));
  }
});
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top