天天看點

Glide 加載圓形圖檔

第一種

Glide.with(context).load(datas.get(position).getImgPath()).asBitmap().centerCrop()
                    .placeholder(R.mipmap.image_error).into(new BitmapImageViewTarget(viewHolder
                    .animalImage) {
                @Override
                protected void setResource(Bitmap resource) {
                   RoundedBitmapDrawable circularBitmapDrawable =
                            RoundedBitmapDrawableFactory.create(context.getResources(), resource);
                    circularBitmapDrawable.setCircular(true);
                    viewHolder.animalImage.setImageDrawable(circularBitmapDrawable);**
                }
            });
           

.placeholder(R.mipmap.image_error):是設定占位符,可有可無。大家使用的時候,可以将自己的ImageView替換掉,就可以了。

第二種

導入依賴

implementation 'com.github.bumptech.glide:glide:4.7.1' 
annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1
           
Glide.with(this)
                .load("http://img5.duitang.com/uploads/item/201506/07/20150607110911_kY5cP.jpeg")
              .apply(RequestOptions.bitmapTransform(new CircleCrop()))
                .into(circle);
           
Glide.with(this)
            .load("http://img.jiuzheng.com/memberlogo/s/57/0a/570af0f48f1e0327178b468d.jpg")
          .apply(RequestOptions.bitmapTransform(new RoundedCorners(20)))//圓角半徑
            .into(round1);

    Glide.with(this)
            .load("http://img.jiuzheng.com/memberlogo/s/57/0a/570af0f48f1e0327178b468d.jpg")
          .apply(RequestOptions.bitmapTransform(new RoundedCorners(60)))//圓角半徑**
            .into(round2);