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.2'
<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.
Properties | Type | Default |
---|---|---|
app:civ_circle_color |
color | WHITE |
app:civ_border |
boolean | true |
app:civ_border_width |
dimension | 4dp |
app:civ_border_color |
color | WHITE |
app:civ_shadow |
boolean | false |
app:civ_shadow_color |
color | BLACK |
app:civ_shadow_radius |
float | 8.0f |
app:civ_shadow_gravity |
center, top, bottom, start or end | 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)
circularImageView.apply {
// Set Circle color for transparent image
circleColor = Color.WHITE
// Set Border
borderColor = Color.RED
borderWidth = 10f
// Add Shadow with default param
shadowEnable = true
// or with custom param
shadowRadius = 15f
shadowColor = Color.RED
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.
Find this library useful? Support it by joining stargazers for this repository ⭐️
And follow me for my next creations 👍
CircularImageView by Lopez Mikhael is licensed under a Apache License 2.0.