How to get finish callback on setImageUrl with Volley library and NetworkImageView?

前端 未结 7 1354
萌比男神i
萌比男神i 2020-12-14 01:18

I\'m trying out the Google\'s new Volley library and it\'s looking sharp and loads images quickly when I use this method setImageUrl:

holder.ima         


        
7条回答
  •  死守一世寂寞
    2020-12-14 01:38

    Another approach (similar to the code from @Simulant above) is to use use a regular ImageView in your xml and then make the image request using Volley.ImageRequest. If you use the Singleton pattern that is recommended by Google it would look something like this:

    ImageView mImageView = (ImageView) findViewById(R.id.myimageview);
    RequestQueue requestQueue = MyVolleySingleton.getInstance(mContext).getRequestQueue();
    ImageRequest mainImageRequest = new ImageRequest(myImageURL,
        new Response.Listener() {
           @Override
           public void onResponse(Bitmap bitmap) {
              // set the image here
              mImageView.setImageBitmap(bitmap);
              // hide the spinner here
           }
        }, 0, 0, null, null);
    
     requestQueue.add(mainImageRequest);
    

    By the way: Make sure that you use a regular ImageView instead of the NetworkImageView or the image will not show properly.

提交回复
热议问题