2016-02-01 90 views
2

我正在使用Glide庫在imageview中加載圖像並使用下面的代碼。在Imageview中使用Glide加載圖像

Glide.with(mActivity) 
       .load(img.getmGridViewImageUrl()) 
       .placeholder(R.color.grey_light) 
       .into(imageHolder.imageView); 

,直至圖像不加載但圖像後得到載荷的ImageView與灰色的佔位符得到看得見,佔位符仍然發生,並顯示圖像後,一些空白。

我該如何解決此問題。如果您有任何想法,請幫助我。

+0

是否確定你沒有在xml中設置imageview的背景 –

+1

不,我沒有使用任何背景在xm文件中的imageview。 ' ' 這是我用於imageView的。 –

+0

嘗試刪除scaleType或adjustViewBounds,你確定你需要這2個屬性 –

回答

1

試試這個代碼。

當我給定高度的ImageView它適用於我。

這裏的佈局

<ImageView 
    android:id="@+id/imgPoster" 
    android:layout_width="fill_parent" 
    android:layout_height="@dimen/height_of_getInspired_list" 
    android:layout_centerVertical="true" 
    android:scaleType="fitXY" 
    android:src="@drawable/default_image"/> 

這裏是我的代碼。

Glide.with(this.context).load(inspiredList.get(position).image) 
.error(R.drawable.default_image) 
.centerCrop() 
.crossFade() 
.placeholder(R.drawable.default_image).into(holder.imgPoster); 
+0

我無法給修復圖像高度imageview,我只能給wrap_content到imageview。 –

+3

你也可以嘗試類似於Glide的畢加索。 http://square.github.io/picasso/ 滑動庫有一些.jpeg文件的問題,它變成綠色或灰色背景。請使用.png文件進行驗證。 另外檢查秤的類型FitXy它適用於我 –

+0

android:scaleType =「fitXY」,它是爲我工作。 – boiledwater

0

試試這個代碼。這將幫助你..

Glide.with(this).load(photo_url) 
      .crossFade() 
      .thumbnail(0.5f) 
      .diskCacheStrategy(DiskCacheStrategy.ALL) 
      .placeholder(R.drawable.plaeholder_image) 
      .listener(new RequestListener<String, GlideDrawable>() { 
       @Override 
       public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) { 
        return false; 
       } 

       @Override 
       public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) { 
        imageView.setImageDrawable(resource); 
        return false; 
       } 
      }) 
      .into(imageView); 

請使用佔位符圖像,而不是顏色。您將能夠使用可繪製的純灰色圖像作爲佔位符圖像。

相關問題