Android上图片加载的解决方案有多种,比较流行的有ImageLoader,Picasso,Fresco,Glide。
lmageLoader是很早的图片加载框架,支持图片下载进度的监听,支持View滚动过程中暂停加载。支持多种缓存策略比如最大先删除,最少使用先删除等。
Picasso简洁轻量,支持图片缓存使用的监控,支持优先级处理,支持延迟加载,自己不参与本地缓存而是交给OkHttp去实现。
public class GlideUtil { public static void loadImage(Context context, String path, ImageView imageView){ Glide.with(context) .load(path) .error(R.drawable.ic_launcher_foreground) .placeholder(R.drawable.ic_autorenew) .thumbnail(0.2f) .skipMemoryCache(true) .diskCacheStrategy(DiskCacheStrategy.ALL) .into(imageView); } //圆形图片 public static void loadciecleImage(Context context, String path, ImageView imageView){ Glide.with(context) .load(path) .error(R.drawable.ic_launcher_foreground) .placeholder(R.drawable.ic_autorenew) .thumbnail(0.2f) .circleCrop() .skipMemoryCache(true) .diskCacheStrategy(DiskCacheStrategy.ALL) .into(imageView); } //圆角图片 public static void loadcornerImage(Context context, String path, ImageView imageView){ Glide.with(context) .load(path) .error(R.drawable.ic_launcher_foreground) .placeholder(R.drawable.ic_autorenew) .thumbnail(0.2f) .transform(new RoundedCorners(20)) .skipMemoryCache(true) .diskCacheStrategy(DiskCacheStrategy.ALL) .into(imageView); } }
Entity里需要加的东西:
适配器需要写的东西有很多,但是都是必要的:
播放视频需要的代码,链接抖音:
最重要的是主页面: