Using Glide for Android, how do I load images from asset and resources?

旧街凉风 提交于 2019-11-30 06:42:36

问题


I want to keep all the transformation, stoke and animations identical and was thinking if we can pass resource ID or asset name in Glide to load it locally?


回答1:


For resource ids, you can use:

Glide.with(fragment)
    .load(R.drawable.resource_id)
    .into(imageView);

For assets, you can construct an asset uri:

Glide.with(fragment)
    .load(Uri.parse("file:///android_asset/<assetName>"))
    .into(imageView);



回答2:


Glide.with(context).load(uri).asBitmap().placeholder(R.drawable.yourimage).error(R.drawable.yourimage).into(yourview); Apart from the above answer if the image URL return null you can load default image into the view as like above.




回答3:


It works when using .asBistmap

String pathUri="file:///android_asset/img/flower.jpg";
 Glide.with(context).asBitmap().load(Uri.parse(pathUri)).into(holder.imgView_post);


来源:https://stackoverflow.com/questions/29982341/using-glide-for-android-how-do-i-load-images-from-asset-and-resources

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!