网络图片加载
来源:互联网 发布:哥贝克力 知乎 编辑:程序博客网 时间:2024/06/05 21:50
import android.content.Context;import android.graphics.Bitmap;import android.graphics.drawable.BitmapDrawable;import android.graphics.drawable.ColorDrawable;import android.graphics.drawable.Drawable;import android.graphics.drawable.TransitionDrawable;import android.widget.ImageView;import com.lidroid.xutils.BitmapUtils;import com.lidroid.xutils.bitmap.BitmapDisplayConfig;import com.lidroid.xutils.bitmap.callback.BitmapLoadFrom;import com.lidroid.xutils.bitmap.callback.DefaultBitmapLoadCallBack;import com.yc.jpyy.R;/** * @类名 网络图片加载 */public class xUtilsImageLoader {// 框架里面设置了缓存和异步操作,不用单独设置线程池和缓存机制(也可以自定义缓存路径)private BitmapUtils bitmapUtils;private Context mContext;public xUtilsImageLoader(Context context) {// TODO Auto-generated constructor stubthis.mContext = context;bitmapUtils = new BitmapUtils(mContext);bitmapUtils.configDefaultLoadingImage(R.drawable.tx);// 默认背景图片bitmapUtils.configDefaultLoadFailedImage(R.drawable.tx);// 加载失败图片bitmapUtils.configDefaultBitmapConfig(Bitmap.Config.ARGB_8888);// 设置图片压缩类型}/** * @category 图片回调函数 */public class CustomBitmapLoadCallBack extendsDefaultBitmapLoadCallBack<ImageView> {@Overridepublic void onLoading(ImageView container, String uri,BitmapDisplayConfig config, long total, long current) {}@Overridepublic void onLoadCompleted(ImageView container, String uri,Bitmap bitmap, BitmapDisplayConfig config, BitmapLoadFrom from) {// super.onLoadCompleted(container, uri, bitmap, config, from);fadeInDisplay(container, bitmap);}@Overridepublic void onLoadFailed(ImageView container, String uri,Drawable drawable) {// TODO Auto-generated method stub}}private static final ColorDrawable TRANSPARENT_DRAWABLE = new ColorDrawable(android.R.color.transparent);/** * @category 图片加载效果 * @param imageView * @param bitmap */private void fadeInDisplay(ImageView imageView, Bitmap bitmap) {// 目前流行的渐变效果final TransitionDrawable transitionDrawable = new TransitionDrawable(new Drawable[] { TRANSPARENT_DRAWABLE,new BitmapDrawable(imageView.getResources(), bitmap) });imageView.setImageDrawable(transitionDrawable);transitionDrawable.startTransition(500);}public void display(ImageView container, String url) {// 外部接口函数bitmapUtils.display(container, url);}}
阅读全文
0 0
- Delphi加载网络图片
- android加载网络图片
- 网络加载图片
- 加载网络图片
- 异步加载网络图片
- SDWebImage 加载网络图片
- 网络图片异步加载
- 异步加载网络图片
- Android加载网络图片
- android加载网络图片
- android 网络加载图片
- 异步加载网络图片
- 网络加载图片
- Flex加载网络图片
- swift 加载网络图片
- 网络加载图片
- ImageView加载网络图片
- 加载显示网络图片
- unity3D 代码实现自定义平面
- Java
- 工厂模式区别
- git 删除本地追踪远程仓库但远程仓库已经不存在的分支
- 基于pyspider的大众点评数据爬取总结
- 网络图片加载
- maven gatling 运行
- Kafka集群动态修改复制因子以及数据留存时间
- oracle密码重置
- Spring 整合JDBCTemplate
- 桥接模式(Bridge)(对象结构型模式)
- 闭包为何可实现变量持久性
- 手机突然没信号!伪基站究竟是怎样搞鬼的?
- 浅谈js中 call, apply, bind 的区别