简体   繁体   中英

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

我想让所有的转换、描边和动画保持相同,并且在想是否可以在 Glide 中传递资源 ID 或资产名称以在本地加载它?

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);
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.

It works when using .asBitmap()

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM