2017-05-05 102 views
0

我在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() –

回答

1

我解決了這個問題。問題在於滑翔。我現在設置的背景沒有滑動,並且工作正常。沒有閃爍。

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