首先导入 Glide。具体依赖可以百度
RoundedCorners roundedCorners = new RoundedCorners(10); RequestOptions options = RequestOptions.bitmapTransform(roundedCorners).override(300, 300); Glide.with(Latte.getApplication()) .load("https://img02.sogoucdn.com/app/a/100520021/41778307d3291ab01cb5db13fe3af3e0") .apply(options) .listener(new RequestListener<Drawable>() { @Override public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) { return false; } @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN) @Override public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) { getActivity().runOnUiThread(() -> mImageview.setBackground(resource)); return false; } }) .submit();
注意回调方法中是子线程,需要在主线程更新 ui