Android 设置图片的四个角 为圆角

首先导入 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() {
                    @Override
                    public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
                        return false;
                    }

                    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
                    @Override
                    public boolean onResourceReady(Drawable resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) {
                        getActivity().runOnUiThread(() -> mImageview.setBackground(resource));
                        return false;
                    }
                })
                .submit();

注意回调方法中是子线程,需要在主线程更新 ui

你可能感兴趣的:(Android,android,图片圆角)