使用数据绑定设置背景图像闪烁

问题描述:

我在android中设置了数据绑定片段的背景。由于后台可以动态改变我设置它在这样的XML:使用数据绑定设置背景图像闪烁

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

的getBackgroundImage()将给背景的路径。 我使用滑行设置这样的背景:

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中预先设定背景的瞬间闪烁。

我该如何避免这种闪烁的背景?

+1

我只能想到两件事情:Glide需要一些时间来加载资源,或者你没有运行executePendingBindings() –

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

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