Search code examples
androidbitmapimageviewdrawablerounded-corners

RoundedImageView - add padding without cropping the image


I am using RoundedImageView by vinc3m1 and I am trying to create an image that has a bitmap in it.
I want the ImageView to be rounded but not the bitmap I place into it, like in this pic:
enter image description here

However, this is the result I am getting: enter image description here

I use padding on the RoundedImageView to achieve this, the View is in a View which contains it and a label; I use the padding in code like this:

int dpPadding = Utils.dpToPx(25); view.getImage().setPadding(dpPadding,dpPadding,dpPadding,dpPadding);

and I see the padding, but I don't want the image inside to have the rounded corners, only the background.

Though it might not be the best way, can any one help?


Solution

  • Scale down your image and add a border to it (to fill the space left by the scaling).

    You can do it using Bitmap.createScaledBitmap.

    To add the border to it, you can create a "white" image with the original size and then combine the two images by overlaying them.

    Then save it and use it in your RoundedImageView.