gpt4 book ai didi

android - picasso 图像未通过 recyclerview 中的 url 加载

转载 作者:行者123 更新时间:2023-11-29 19:05:36 25 4
gpt4 key购买 nike

Picasso.with(context).load("http://api.learn2crack.com/android/images/donut.png ").resize(218, 192).centerCrop().into(holder.coverImageViewa);

最佳答案

自定义 picasso .java

import android.content.Context;
import android.util.Log;

import com.jakewharton.picasso.OkHttp3Downloader;
import com.squareup.picasso.Picasso;

/**
* Created by Hrishikesh Kadam on 19/12/2017
*/

public class CustomPicasso {

private static String LOG_TAG = CustomPicasso.class.getSimpleName();
private static boolean hasCustomPicassoSingletonInstanceSet;

public static Picasso with(Context context) {

if (hasCustomPicassoSingletonInstanceSet)
return Picasso.with(context);

try {
Picasso.setSingletonInstance(null);
} catch (IllegalStateException e) {
Log.w(LOG_TAG, "-> Default singleton instance already present" +
" so CustomPicasso singleton cannot be set. Use CustomPicasso.getNewInstance() now.");
return Picasso.with(context);
}

Picasso picasso = new Picasso.Builder(context).
downloader(new OkHttp3Downloader(context))
.build();

Picasso.setSingletonInstance(picasso);
Log.w(LOG_TAG, "-> CustomPicasso singleton set to Picasso singleton." +
" In case if you need Picasso singleton in future then use Picasso.Builder()");
hasCustomPicassoSingletonInstanceSet = true;

return picasso;
}

public static Picasso getNewInstance(Context context) {

Log.w(LOG_TAG, "-> Do not forget to call customPicasso.shutdown()" +
" to avoid memory leak");

return new Picasso.Builder(context).
downloader(new OkHttp3Downloader(context))
.build();
}
}

build.gradle(模块:应用程序)

android {

...

}

dependencies {

...

compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0'
}

用法 -

CustomPicasso.with(context)
.load("http://api.learn2crack.com/android/images/donut.png")
.resize(218, 192)
.centerCrop()
.into(holder.coverImageViewa);

关于android - picasso 图像未通过 recyclerview 中的 url 加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47369895/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com