【问题标题】:Flickering of background image when it is set with data binding设置数据绑定时背景图片闪烁
【发布时间】:2017-05-05 12:41:28
【问题描述】:

我在android中使用数据绑定设置片段的背景。由于背景可以动态变化,我在 xml 中设置它是这样的:

app:image="@{variable.getBackgroundImage()}"

getBackgroundImage() 将给出背景的路径。 我正在使用 glide 来设置这样的背景:

Glide.with(view.getContext()).load(url + File.separator + path)
                    .dontAnimate()
                    .into(new SimpleTarget<GlideDrawable>() {
                        @Override
                        public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) {
                            view.setBackground(resource);
                        }
                    });

图像正在设置,但 xml 中的预设背景会瞬间闪烁。

如何避免这种背景闪烁?

【问题讨论】:

  • 我只能想到两件事:要么 Glide 需要一点时间来加载资源,要么你没有运行executePendingBindings()

标签: android xml data-binding android-glide


【解决方案1】:

我解决了这个问题。问题在于滑行。我现在正在设置没有滑动的背景,并且工作正常。没有闪烁。

BitmapDrawable bd = new BitmapDrawable(view.getContext().getResources(), BitmapFactory.decodeFile(url + File.separator + path));
            view.setBackground(bd);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-30
    • 2021-05-19
    • 2016-03-19
    • 2012-12-03
    • 2018-12-29
    • 1970-01-01
    • 2014-03-19
    • 1970-01-01
    相关资源
    最近更新 更多