当前位置: 首页 > 科技观察

Android图片平滑滚动组件Glide

时间:2023-03-11 23:50:03 科技观察

Glide是一个基于Android的图片加载和图片缓存组件,可以在Android设备上高性能地读取、解码和显示图片和视频。Glide可以在设备本地缓存远程图片、视频、动画图片等,提高用户浏览图片的流畅体验。Glide的核心功能是提高图片列表滚动的性能,Glide也可以满足读取、改变大小和显示远程图片的性能需求。使用Glide最简单的示例代码如下:://goo.gl/h8qOq7").into(imageView);}//Foralist:@OverridepublicViewgetView(intposition,Viewrecycled,ViewGroupcontainer){finalImageViewmyImageView;if(recycled==null){myImageView=(ImageView)inflater.inflate(R.layout.my_image_view,container,false);}else{myImageView=(ImageView)recycled;}Stringurl=myUrls.get(position);Glide.with(myFragment).load(url).centerCrop().placeholder(R.drawable.loading_spinner).crossFade().into(myImageView);returnmyImageView;}将Volley通信框架应用到GlideVolley是Glide的可选选项,可以支持http/https读取图片。使用Gradle:dependencies{compile'c??om.github.bumptech.glide:volley-integration:1.0.+'compile'c??om.mcxiaoke.volley:library:1.0.+'}或使用Maven:com.github.bumptech.glidevolley-integration1.0.1jarcom.mcxiaoke.volleylibrary1.0.5aar然后在Activity或者Application中注册Volley插件:publicvoidonCreate(){Glide.get(this).register(GlideUrl.class,InputStream.class,newVolleyUrlLoader.Factory(yourRequestQueue));...}这样所有的请求都会通过Volley。在Glide中应用OkHttp通信框架除了Volley,OkHttp通信框架也可以在Glide中使用。OkHttp也支持http/https读取图片。使用Gradle:dependencies{compile'c??om.github.bumptech.glide:okhttp-integration:1.0.+'compile'c??om.squareup.okhttp:okhttp:2.0.+'}或使用Maven:com.github.bumptech.glideokhttp-integration1.0.1jarcom.squareup.okhttpokhttp2.0.0jar然后在Activity或者Application中注册OkHttp插件:publicvoidonCreate(){Glide.get(this).register(GlideUrl.class,InputStream.class,newOkHttpUrlLoader.Factory(yourOkHttpClient));...}总结如果你的Android应用涉及远程图片的处理,那么Glide组件可以帮助你在图片和视频方面优化您的应用程序。软件首页软件文档软件下载