【问题标题】:Load from URL to ImageView with Picasso without white flash on ImageView使用 Picasso 从 URL 加载到 ImageView,而 ImageView 上没有白色闪烁
【发布时间】:2015-08-08 15:51:11
【问题描述】:

我正在使用 Square 的 Picasso 库将 URL 字符串加载到 ImageView 中。我用 Timer 在数组或 URL 上多次调用它来更改 ImageView 图像。

第一次,当 Picasso 加载 URL 内容时,每次 ImageView 更新时,它都会闪烁白色。

Picasso 缓存内容后,ImageView 会在没有 flash 的情况下发生变化。

如何阻止 ImageView 闪烁白色?

Picasso.with(getApplicationContext()).load(currentUrl).into(img, new Callback() {
                    @Override
                    public void onSuccess() {
                        mProgress.dismiss();
                    }

                    @Override
                    public void onError() {
                        mProgress.dismiss();
                    }
                });

【问题讨论】:

    标签: android picasso


    【解决方案1】:

    有同样的问题,通过添加 noPlaceHolder 指令解决它:

    Picasso.with(getApplicationContext())
        .load(currentUrl)
        .noPlaceholder()
        .into(img, new Callback() {
                        @Override
                        public void onSuccess() {
                            mProgress.dismiss();
                        }
    
                        @Override
                        public void onError() {
                            mProgress.dismiss();
                        }
                    });
    

    默认情况下,Picasso 将清除目标 ImageView 以确保在视图被回收的情况下的行为。此方法将阻止该行为并保留任何已设置的图像。

    Picasso Documentaton

    【讨论】:

      【解决方案2】:
      ImageView iv = findViewById(R.id.iv);
      Picass().get()
      .load("Image Url")
      .noPlaceHolder()
      .into(iv);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-06-27
        • 1970-01-01
        • 2015-06-29
        • 1970-01-01
        • 1970-01-01
        • 2018-02-20
        • 2016-09-26
        • 2016-07-03
        相关资源
        最近更新 更多