Android Glide加载圆角图片及圆形图片

作者: 带带我 | 来源:发表于2019-10-23 15:53 被阅读0次

加载圆角图片

public static void displayRoundrect(Context context, ImageView imageView, String url, int corner)  throws IllegalArgumentException{
        //加载圆角矩形 corner 圆角度数
        if (imageView == null) {
            throw new IllegalArgumentException("argument error");
        }
        //如果加载其他形状的可以设置不同的 GlideRoundedCorners.CornerType
        //如 GlideRoundedCorners.CornerType.TOP,GlideRoundedCorners.CornerType.TOP_LEFT_BOTTOM_RIGHT 等等
        GlideRoundedCorners c = new GlideRoundedCorners(corner, GlideRoundedCorners.CornerType.ALL);
        RequestOptions options = new RequestOptions().optionalTransform(c);
        Glide.with(context)
                .load(url)
                .apply(options)
                .into(imageView);

    }

加载圆形图片

public static void displayCircle(Context context, ImageView imageView, String url)  throws IllegalArgumentException{
        //加载圆形图片
        if (imageView == null) {
            throw new IllegalArgumentException("argument error");
        }
        RequestOptions options = new RequestOptions()
                  //圆形
                .circleCrop()
                  //占位图
                .placeholder(R.drawable.user_default_head)
                  //加载失败图
                .error(R.drawable.user_default_head);
        Glide.with(context)
                .load(url)
                .apply(options)
                .into(imageView);
    }

相关文章

网友评论

    本文标题:Android Glide加载圆角图片及圆形图片

    本文链接:https://www.haomeiwen.com/subject/khekvctx.html