【问题标题】:Why Picasso is not using imageView.getContext()?为什么毕加索不使用 imageView.getContext()?
【发布时间】:2016-12-13 19:00:11
【问题描述】:

愚蠢的问题:

如果上下文可以从 imageView 本身获得,为什么还要显式传递它呢? 如果毕加索这样做会有什么问题:

Picasso.load(url).into(imageView);

而不是

Picasso.with(context).load(url).into(imageView);

?

【问题讨论】:

    标签: android android-context picasso


    【解决方案1】:

    上下文用于初始化磁盘缓存、加载本地资源以及与内容提供者通信,into 并不总是被调用的操作方法。还有get()fetch()

    【讨论】:

    • 所以如果我做 Picasso.with(imageView.getContext()).load(url).into(imageView) 没问题?
    • 一点也不!我们还确保我们在您提供的任何Context 上致电getApplicationContext(),以免对视图或活动有任何强烈引用。
    【解决方案2】:
    ImageView imageView=(ImageView)header.findViewById(R.id.userImage);
    Picasso.with(imageView.getContext()).load("https://secure.gravatar.com/avatar/#HASH#?s=64&d=mm&r=g").into(imageView);
    

    【讨论】:

    • 这不是一个“如何”的问题,而是一个“为什么”的问题
    猜你喜欢
    • 2016-10-26
    • 1970-01-01
    • 2017-07-14
    • 2016-06-18
    • 2018-08-26
    • 1970-01-01
    • 1970-01-01
    • 2017-10-14
    相关资源
    最近更新 更多