相关疑难解决方法(0)

如何在Picasso中使用磁盘缓存?

我正在使用Picasso在我的Android应用程序中显示图像:

/**
* load image.This is within a activity so this context is activity
*/
public void loadImage (){
    Picasso picasso = Picasso.with(this); 
    picasso.setDebugging(true);
    picasso.load(quiz.getImageUrl()).into(quizImage);
}
Run Code Online (Sandbox Code Playgroud)

我已启用调试,它始终显示红色和绿色.但从不显示黄色

现在,如果我下次加载相同的图像并且互联网不可用,则不会加载图像.

问题:

  1. 它没有本地磁盘缓存吗?
  2. 如何启用磁盘缓存,因为我将多次使用相同的图像.
  3. 我需要为android清单文件添加一些磁盘权限吗?

android caching image picasso

116
推荐指数
5
解决办法
10万
查看次数

毕加索将图像加载到目标中

我正在使用Picasso下载各种图像.通常,我只是在显示这些,ImageView但在这种情况下,我想对它们进行强有力的引用,以便我可以在不同的地方使用它们,而无需返回缓存或重新下载它们.以下是我试图这样做的方法(请注意,本课程还有更多内容 - 我只是将其缩小到与此问题相关的部分):

public class MapLayer {

    private Context mContext;
    private String mType;
    private Drawable mIcon = null;

    public MapLayer (Context context, String type) {
        mContext = context;
        mType = type;
        downloadIcon();
    }

    public Drawable getIcon() {return mIcon;}

    private void downloadIcon() {

        String url = mContext.getString(R.string.maps_icon_url).replace("${type}", mType));

        Target target = new Target() {
            @Override
            public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
                Log.d(TAG, "on bitmap loaded");
                mIcon = new BitmapDrawable(mContext.getResources(), bitmap);
            }

            @Override
            public void onBitmapFailed(Drawable errorDrawable) {
                Log.d(TAG, …
Run Code Online (Sandbox Code Playgroud)

android picasso

5
推荐指数
1
解决办法
9175
查看次数

标签 统计

android ×2

picasso ×2

caching ×1

image ×1