This is an Android project allowing to realize a circular ImageView in the simplest way possible.
To make a circular ImageView add CircularImageView in your layout XML and add CircularImageView library in your project or you can also grab it via Gradle:
implementation 'com.mikhaellopez:circularimageview:4.0.1'
<com.mikhaellopez.circularimageview.CircularImageView
android:layout_width="250dp"
android:layout_height="250dp"
android:src="@drawable/image"
app:civ_border_color="#3f51b5"
app:civ_border_width="4dp"
app:civ_shadow="true"
app:civ_shadow_radius="10"
app:civ_shadow_color="#3f51b5"/>
You must use the following properties in your XML to change your CircularImageView.
app:civ_circle_color
(color) -> default WHITEapp:civ_border
(boolean) -> default trueapp:civ_border_color
(color) -> default WHITEapp:civ_border_width
(dimension) -> default 4dpapp:civ_shadow
(boolean) -> default falseapp:civ_shadow_color
(color) -> default BLACKapp:civ_shadow_radius
(float) -> default 8.0fapp:civ_shadow_gravity
(center, top, bottom, start or end) -> default bottom
ℹ️ You can also use android:elevation
instead of app:civ_shadow
to have default Material Design elevation.
val circularImageView = findViewById<CircularImageView>(R.id.circularImageView)
// Set Circle color for transparent image
circularImageView.circleColor = Color.WHITE
// Set Border
circularImageView.borderColor = Color.RED
circularImageView.borderWidth = 10f
// Add Shadow with default param
circularImageView.shadowEnable = true
// or with custom param
circularImageView.shadowRadius = 15f
circularImageView.shadowColor = Color.RED
circularImageView.shadowGravity = CircularImageView.ShadowGravity.CENTER
CircularImageView circularImageView = findViewById(R.id.circularImageView);
// Set Circle color for transparent image
circularImageView.setCircleColor(Color.WHITE);
// Set Border
circularImageView.setBorderColor(Color.RED);
circularImageView.setBorderWidth(10);
// Add Shadow with default param
circularImageView.setShadowEnable(true);
// or with custom param
circularImageView.setShadowRadius(15);
circularImageView.setShadowColor(Color.RED);
circularImageView.setBackgroundColor(Color.RED);
circularImageView.setShadowGravity(CircularImageView.ShadowGravity.CENTER);
- By default the ScaleType is CENTER_CROP. You can also used CENTER_INSIDE but the others one are not supported.
- Enabling adjustViewBounds is not supported as this requires an unsupported ScaleType.
Stack OverFlow:
I realized this project using this post:
- Create circular image view in android
- How to add a shadow and a border on circular imageView android?
CircularImageView by Lopez Mikhael is licensed under a Apache License 2.0.