How to Make an ImageView with Rounded Corners in Android

How to Make an ImageView with Rounded Corners in Android

22 May 2024 Stephan Petzl Leave a comment Tech-Help

In Android, an ImageView is a rectangle by default. If you want to make it a rounded rectangle, there are several approaches you can take. This guide will walk you through the most effective methods to achieve rounded corners on your ImageView, based on the latest and most relevant solutions available.

Using ShapeableImageView

Starting with version 1.2.0-alpha03 of the Material Components Library, you can easily make rounded corners using ShapeableImageView. This approach is straightforward and leverages the latest advancements in the Android ecosystem.

XML Implementation

First, add the ShapeableImageView to your layout XML file:

    app:srcCompat="@drawable/ic_image" />

Next, define the rounded corners in your themes.xml:

    <style name="roundedImageView" parent="">
    <item name="cornerFamily">rounded</item>
    <item name="cornerSize">8dp</item>

Programmatic Implementation

You can also set the rounded corners programmatically:

    float radius = getResources().getDimension(R.dimen.default_corner_radius);
    .setAllCorners(CornerFamily.ROUNDED, radius)

Alternative Methods

If you are working with older versions of Android or prefer different methods, here are some other approaches:

Using CardView

Another simple way is to wrap your ImageView in a CardView and set the corner radius:

        android:scaleType="centerCrop" />

Using RoundedBitmapDrawable

For API level 21 and above, you can use RoundedBitmapDrawable:

    RoundedBitmapDrawable dr = RoundedBitmapDrawableFactory.create(getResources(), src);


These methods provide you with various options to create rounded corners on an ImageView in Android. Depending on your project requirements and API levels, you can choose the most suitable approach.

Enhancing Your Development with Repeato

As you focus on creating visually appealing and functional mobile applications, remember that testing is a crucial part of the development process. Our product, Repeato, is a no-code test automation tool for iOS and Android. It allows you to create, run, and maintain automated tests for your apps efficiently.

Repeato is particularly beneficial for mobile developers as it enables them to concentrate on creating a great product instead of spending excessive time on test automation. Additionally, it allows developers to delegate test automation tasks to non-technical colleagues or QA teams.

For more information on how Repeato can streamline your mobile app testing, visit our blog or check out our documentation.

Like this article? there’s more where that came from!