ImageView in circular through xml

前端 未结 27 1439
死守一世寂寞
死守一世寂寞 2020-11-22 10:35

I\'d Like to make any image from my ImageView to be circular with a border.

I searched but couldn\'t find any useful information (anything that I tried

27条回答
  •  清歌不尽
    2020-11-22 10:53

    With the help of glide library and RoundedBitmapDrawableFactory class it's easy to achieve. You may need to create circular placeholder image.

    Glide V4:

    Glide.with(context).load(url).apply(RequestOptions.circleCropTransform()).into(imageView);
    

    Glide V3:

        Glide.with(context)
            .load(imgUrl)
            .asBitmap()
            .placeholder(R.drawable.placeholder)
            .error(R.drawable.placeholder)
            .into(new BitmapImageViewTarget(imgProfilePicture) {
                @Override
                protected void setResource(Bitmap resource) {
                    RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(context.getResources(),
                            Bitmap.createScaledBitmap(resource, 50, 50, false));
                    drawable.setCircular(true);
                    imgProfilePicture.setImageDrawable(drawable);
                }
            });
    

    For Picasso RoundedTransformation, this is a really great solution that gives an additional option of rounding image at either top or bottom edge.

提交回复
热议问题