Android基础(41)图片加载框架

2019-03-19  本文已影响0人  perry_Fan

1)图片库对比
2)Glide源码解析
3)图片框架缓存实现
4)LRUCache原理。LruCache默认缓存大小
5)图片加载原理。自己去实现图片库,怎么做?
6)Glide使用什么缓存?Glide内存缓存如何控制大小?

一. 图片库对比

Picasso、Glide、Fresco 三种常见的网络框架

共同点:
差异点:
  1. Picasso
  1. Glide
  1. Fresco
二. Glide源码分析

https://blog.csdn.net/sinyu890807/column/info/15318

三. 显示图片高度自适应

在XML布局中 imageView部分不要忘记设置:

       android:scaleType="fitXY"  
       android:adjustViewBounds="true"  
Glide.with(mActivity)
                        .load(campDetailBean.getCover4())
                        .asBitmap()
                        .into(new SimpleTarget<Bitmap>(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) {
                            @Override
                            public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                                int imageWidth = resource.getWidth();
                                int imageHeight = resource.getHeight();
                                ViewGroup.LayoutParams para = imgBackground.getLayoutParams();

                                int maxHeight = DensityUtils.dip2px(400);
                                int height = (int) ((float) imgBackground.getWidth() / imageWidth * imageHeight);
                                if (height > maxHeight) height = maxHeight;
                                para.height = height;
                                imgBackground.setLayoutParams(para);

                                Glide.with(mActivity)
                                        .load(campDetailBean.getCover4())
                                        .asBitmap()
                                        .into(imgBackground);

                            }
                        });

上一篇下一篇

猜你喜欢

热点阅读