AndroidManifest添加网络权限:
AndroidManifest添加网络安全配置文件:android:networkSecurityConfig="@xml/network_security_config"
添加Glide依赖库:implementation'com.github.bumptech.glide:glide:4.5.0'
annotationProcessor'com.github.bumptech.glide:compiler:4.5.0'
设置图片的控件,在控件内定义好了宽高,设置ID,初始化控件:ImageViewimg_music;
img_music=itemView.findViewById(R.id.img_music);
//with参数:上下文
Glide.with(mContext)
//.load参数:imgURL
.load("/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2137960608,132385527&fm=26&gp=0.jpg")
//.into参数:控件
.into(holder.img_music);
然后就可以在对应的位置加载到网络的图片了!
如果需要加载GIF动画的话,可能会需要一个GifImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/gif_v"/>
和之前的方式一样,初始化控件:privateGifImageViewimg;
img=findViewById(R.id.gif_v);
然后Glide.with(this)
.asGif()
.load("/image_search/src=http%3A%2F%2Fb-%2Fuploads%2Fitem%2F11%2F04%2F1104110413_XzVAk.thumb.700_0.gif&refer=http%3A%2F%2Fb-&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1620448938&t=4b33d586fadfbd83c6d8c99394389771")
.into(img);
就可以了。
其它的参数:
如果觉得《android studio调用图片 Android studio加载网络图片_Glide》对你有帮助,请点赞、收藏,并留下你的观点哦!