Glide加載圖片相比於Picasso而言性能較好,又比Fresco輕巧,而且又支持加載gif動圖,是Google 推薦、專注平滑的滾動、簡單易用、可擴展的一款圖片加載框架。但是使用時還是會遇到一些問題。
1、同時和RoundedImageView使用時,又恰巧RoundedImageView設置了圓角或者圓形,那么在很多手機上會出現,開始有圓角,滑動過去再返回時,圓角消失了。所以加載圓形時還是配合GlideCircleTransform使用比較穩妥。
2、我們在加載的時候一般會設置占位符 ,我們會加一個placeholder (loadingImage)如下
Glide.with(mContext).load(path).placeholder(loadingImage).error(errorImageView).into(mImageView);
但是會發現一直顯示占位符的圖片,不顯示path 的路徑, 這個原因應該是緩存問題。只要加上dontAnimate() 或者把Placeholder (loadingImage)的loadingimage 換成mImageview.getdrawable如下:
Glide.with(mContext).load(path).placeholder(loadingImage).dontAnimate().error(errorImageView).into(mImageView);
3、加載gif時,不可以配合使用RoundedImageView,否則gif只能顯示成圖片。
還有,敲重點!!!在性能比較好的新手機上,可以正常的流暢的播放 但是在性能比較差的舊手機就不行了 有很明顯的卡頓現象。
然后百度找原因:glide gif 卡 發現大部分都是以 .diskCacheStrategy(DiskCacheStrategy.SOURCE) 就解決了,但是有的手機加上還是mi有用啊。 So,無奈。glide在除了gif加載外適用還是比較好的。
4、友盟上經常報出很多關於Glide的崩潰,如下
You cannot start a load for a destroyed activity at com.bumptech.glide.manager.RequestManagerRetriever.assertNotDestroyed(RequestManagerRetriever.java:134) at com.bumptech.glide.manager.RequestManagerRetriever.get(RequestManagerRetriever.java:125) at com.bumptech.glide.Glide.with(Glide.java:641)
究其原因,因為Glide是一個網絡請求, 會在子線程中進行網絡請求,我剛進入程序,Glide還正在子線程中請求數據,這是我就把MainActivity干掉了(onDestroy),Glide沒有提前中止請求,所以就崩潰了呀。所以在使用之前還是先加個判斷吧:
if (context != null) { Glide.with(context).load(url).error(default_image).crossFade().into(imageView); } else { Log.e(TAG, "Picture loading failed,context is null"); }
所以,使用Glide請注意完美規避以上坑。
By LiYing