- The image size is too large.
- Layout overlapping is not proper.
And as we know CardView by default had the previous articles attribute so by using it, making the circular view is an easy task.
Now without wasting more time, allow me to show you guys "How To Make It Happen".
Requirement:
First, get some good-resolution images and add them to a drawable folder. So we have added an image of good-resolution i.e. 191*186 ↓
Code:
Explanation:
As we are focusing to display a small circular image, we had considered and had fixed width and height as 150dp * 148dp.
Now give approximate half of the width or height size to its corner, we had considered and had fixed cardCornerRadius as 75dp.
Output:
Update (September 2026): circular images with ShapeableImageView and Jetpack Compose
Wrapping an ImageView in a CardView with a huge corner radius works, but there are two cleaner ways today: ShapeableImageView (Material Components) for XML and Modifier.clip(CircleShape) for Compose.
1. XML: ShapeableImageView
Add com.google.android.material:material, then define a shape style that rounds every corner by 50%:
<!-- res/values/styles.xml -->
<style name="CircleImage">
<item name="cornerFamily">rounded</item>
<item name="cornerSize">50%</item>
</style>
<!-- layout -->
<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/avatar"
android:layout_width="96dp"
android:layout_height="96dp"
android:scaleType="centerCrop"
android:src="@drawable/profile"
android:contentDescription="Profile photo"
app:shapeAppearanceOverlay="@style/CircleImage"
app:strokeColor="@color/white"
app:strokeWidth="2dp" />
Keep the width and height equal. Otherwise the 50% radius produces an oval instead of a circle. You can also build the same shape in Kotlin:
binding.avatar.shapeAppearanceModel = binding.avatar.shapeAppearanceModel
.toBuilder()
.setAllCornerSizes(ShapeAppearanceModel.PILL)
.build()
2. Text on top of the circle (the CardView layout from this post)
If you still want the label over the picture as in the original example, put the ShapeableImageView and the TextView in a FrameLayout (or ConstraintLayout) and set android:layout_gravity="center" on the text. You no longer need a CardView just to get round corners.
3. Jetpack Compose
@Composable
fun CircleAvatar() {
Box(contentAlignment = Alignment.Center) {
Image(
painter = painterResource(id = R.drawable.profile),
contentDescription = "Profile photo",
contentScale = ContentScale.Crop,
modifier = Modifier
.size(96.dp)
.clip(CircleShape)
.border(2.dp, Color.White, CircleShape)
)
Text(
text = "Vinod",
color = Color.White,
fontWeight = FontWeight.Bold
)
}
}
Order matters in Compose: apply size first, then clip, then border, and pass the same shape (CircleShape) to both clip and border so the outline follows the circle exactly.
Which one should you use?
- XML/View app:
ShapeableImageViewwith a 50% corner size. - Compose app:
Modifier.clip(CircleShape). - Old code: the CardView approach still works and needs no extra library, but you cannot draw a stroke around the circle as easily.



Comments
Post a Comment