1

I have ImageView and it has background named avatar_background that makes circle.

 <ImageView
                    android:scaleType="centerCrop"
                    android:background="@drawable/avatar_background"
                    android:id="@+id/avatarImage"
                    android:layout_width="70dp"
                    android:layout_height="70dp"
                    android:src="@drawable/ic_user" />

And I get Image from Gallery of device and set this Image Uri to ImageView.

registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
                    if (it.resultCode == RESULT_OK) {
                        avatarUri = it.data?.data!!
                        binding.avatarImage.setImageURI(avatarUri)
                        binding.avatarImage.scaleType = ImageView.ScaleType.CENTER_INSIDE
                    }
                }

But when Images is attached to this ImageView, It shows square image, not circle.

which means avatar_background is not applied well even though I set scaleType to centerCrop, I did with centerInside also, but same as not working.

How can I programmed Image URI with circle ?

Hyejung
  • 902
  • 1
  • 8
  • 22
  • 1
    If you want the background to define the clip bounds for the `View`, you'd need to set `clipToOutline = true` on it (assuming you haven't changed its `ViewOutlineProvider` from the default): https://stackoverflow.com/a/30692236. There's a corresponding XML attribute, but it's not available until API level 31. – Mike M. Feb 13 '23 at 14:34

0 Answers0