Android Glide not support StateListDrawable

303 views
Skip to first unread message

gjdyo...@126.com

unread,
Feb 27, 2017, 1:52:05 AM2/27/17
to Glide
I try to use StateListDrawable R.drawable.image in Glide, but it always show the error R.drawable.default_image. However, if replace R.drawable.image with R.drawable.image_add_sel, it will show normally. I use it as below:
Glide.with(context)                                  
 .load(R.drawable.image)                                 
 .error(R.drawable.default_image)            
 .placeholder(R.drawable.default_image)       
 .diskCacheStrategy(DiskCacheStrategy.RESULT) 
 .into(imageView);
I find the root cause is :
in com.bumptech.glide.load.data.FileDescriptorLocalUriFetcher.java
    @Override
    protected ParcelFileDescriptor loadResource(Uri uri, ContentResolver contentResolver) throws FileNotFoundException {
        return contentResolver.openAssetFileDescriptor(uri, "r").getParcelFileDescriptor();
    }
It will throw "This file can not be opened as a file descriptor; it is probably compressed" exception, it not support StateListDrawable  resource.

I think it's common to use StateListDrawable in ImageView, so could this issue be fixed? Thanks.




Sam Judd

unread,
Feb 27, 2017, 11:47:27 AM2/27/17
to gjdyo...@126.com, Glide
Glide doesn't support Drawable types other than simple BitmapDrawables. If you're interested in adding support, I'd be willing to look at PR. In general there's not a lot of value to using Glide to load standard resources. 

Sam

--
You received this message because you are subscribed to the Google Groups "Glide" group.
To unsubscribe from this group and stop receiving emails from it, send an email to glidelibrary+unsubscribe@googlegroups.com.
To post to this group, send email to glidel...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/glidelibrary/3e162c4a-d37f-47f7-b02e-8746cf85319b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Róbert Papp

unread,
Feb 27, 2017, 2:57:16 PM2/27/17
to Glide, gjdyo...@126.com
Even if it went past that exception https://github.com/bumptech/glide/issues/350 would prevent continuing forward.


On Monday, February 27, 2017 at 4:47:27 PM UTC, Sam Judd wrote:
Glide doesn't support Drawable types other than simple BitmapDrawables. If you're interested in adding support, I'd be willing to look at PR. In general there's not a lot of value to using Glide to load standard resources. 

Sam
On Sun, Feb 26, 2017 at 10:52 PM, <gjdyo...@126.com> wrote:
I try to use StateListDrawable R.drawable.image in Glide, but it always show the error R.drawable.default_image. However, if replace R.drawable.image with R.drawable.image_add_sel, it will show normally. I use it as below:
Glide.with(context)                                  
 .load(R.drawable.image)                                 
 .error(R.drawable.default_image)            
 .placeholder(R.drawable.default_image)       
 .diskCacheStrategy(DiskCacheStrategy.RESULT) 
 .into(imageView);
I find the root cause is :
in com.bumptech.glide.load.data.FileDescriptorLocalUriFetcher.java
    @Override
    protected ParcelFileDescriptor loadResource(Uri uri, ContentResolver contentResolver) throws FileNotFoundException {
        return contentResolver.openAssetFileDescriptor(uri, "r").getParcelFileDescriptor();
    }
It will throw "This file can not be opened as a file descriptor; it is probably compressed" exception, it not support StateListDrawable  resource.

I think it's common to use StateListDrawable in ImageView, so could this issue be fixed? Thanks.




--
You received this message because you are subscribed to the Google Groups "Glide" group.
To unsubscribe from this group and stop receiving emails from it, send an email to glidelibrary...@googlegroups.com.
Message has been deleted

gjdyo...@126.com

unread,
Feb 27, 2017, 9:25:46 PM2/27/17
to Glide
Thanks for your prompt and kind reply. Now I find a workaround to fix this issue as below:

Glide.with(context)                                  
     .load(R.drawable.image)                                 
     .error(R.drawable.image)             
     .placeholder(R.drawable.image)       
     .diskCacheStrategy(DiskCacheStrategy.RESULT) 
     .into(imageView);
 
In addition, I think it's necessary to add XML drawable support in Glide.

We always use Glide in GridView or ListView to async loading images, but sometimes we want to
show xml drawable in GridView or ListView meanwhile. If we use ImageView.setImageDrawable(***) to load drawable, it will not show correctly for the views reusing in GridView and ListView. At this moment, we'd better use Glide to show drawable, too.

Thanks.

François Blavoet

unread,
Feb 28, 2017, 2:17:13 AM2/28/17
to Glide, gjdyo...@126.com
> but sometimes we want to
>show xml drawable in GridView or ListView meanwhile. If we use ImageView.setImageDrawable(***) to load drawable, it will not show correctly for the views reusing in >GridView and ListView.

I guess you mean that when glide reuse a view, there is a chance that it will display what was loading there ?  
It is very easy to use the same view for both glide and classic view.setImageResource calls.

In this second case, you just have to call `Glide.clear(imageview);` in order to tell glide to release any resource and to stop any load associated  with that view. Then you can manipulate this view yourself.

gjdyo...@126.com

unread,
Feb 28, 2017, 7:18:48 AM2/28/17
to Glide
Yeah, many thanks for your reply. That really resolves my issue. Thanks.
Reply all
Reply to author
Forward
0 new messages