簡體   English   中英

使用Picasso庫從https url加載圖像時出錯

[英]Getting error on loading image from https url using Picasso library

在我的應用程序中,我正在嘗試使用Picasso庫從https URL加載圖像。我無法將圖像加載到ImageView中。 我正在使用Picasso 2.5.2,我將圖像設置如下:

  Picasso.with(mContext)
            .load(GlobalVariable.movieDetails.get(0).getVideo_cover_image())
            .placeholder(R.drawable.animation_placeholder)
            .error(R.drawable.animation_placeholder)
            .into(iv_image);

嘗試這個

if (TextUtils.isEmpty(imageUrl) && !isValidUrl(imageUrl)) {
                iv_image.setImageResource(R.drawable.default);

            } else {
                Picasso.with(context)
                        .load(imageUrl)
                        .resize(70, 70)//if you want resize image
                        .centerInside()
                        .into(iv_image, new com.squareup.picasso.Callback() {
                            @Override
                            public void onSuccess() {

                            }

                            @Override
                            public void onError() {
                                iv_image.setImageResource(R.drawable.default);
                            }
                        });
            }

驗證網址

 public static boolean isValidUrl(String string) {

    boolean b = Patterns.WEB_URL.matcher(string).matches();
    return b;
}

畢加索為圖像加載提供了一個監聽器。

使用下面的代碼並檢查圖像加載狀態是成功還是錯誤。

 Picasso.with(mContext)
        .load(GlobalVariable.movieDetails.get(0).getVideo_cover_image())
        .placeholder(R.drawable.animation_placeholder)
        .error(R.drawable.animation_placeholder)
        .into(iv_imagenew, 
                    new com.squareup.picasso.Callback() {
                    @Override
                    public void onSuccess() {
                          //Image Loaded
                    }

                    @Override
                    public void onError() {
                         //Error while Loading
                    }
                });

請使用picaso的resize(horizo​​ntalSize,verticalSize)方法調整圖像大小。 可能是你的圖像大小很大,這就是為什么它不會加載所以,請嘗試調整大小(horizo​​ntalSize,verticalSize)

Picasso.with(context)
       .load(GlobalVariable.movieDetails.get(0).getVideo_cover_image())
       .placeholder(R.drawable.animation_placeholder)
       .error(R.drawable.animation_placeholder)
       .into(iv_image);
       .resize(600, 200) // resizes the image to these dimensions (in pixel). does not respect aspect ratio
       .into(imageViewResize);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM