lopspower/CircularImageView

Create circular ImageView in Android in the simplest way possible

Kotlin

1,958

154 commits

updated Oct 11, 2022

See the code

README

CircularImageView

sample

Platform API Maven Central Twitter

This is an Android project allowing to realize a circular ImageView in the simplest way possible.

Android app on Google Play

USAGE

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.3.1'

XML

<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="10dp"
    app:civ_shadow_color="#3f51b5"/>

You must use the following properties in your XML to change your CircularImageView.

PropertiesTypeDefault
app:civ_circle_colorcolorWHITE
app:civ_circle_color_startcolorciv_circle_color
app:civ_circle_color_endcolorciv_circle_color
app:civ_color_directionleft_to_right, right_to_left, top_to_bottom or bottom_to_topleft_to_right
app:civ_borderbooleantrue
app:civ_border_widthdimension4dp
app:civ_border_colorcolorWHITE
app:civ_border_color_startcolorciv_border_color
app:civ_border_color_endcolorciv_border_color
app:civ_border_color_directionleft_to_right, right_to_left, top_to_bottom or bottom_to_topleft_to_right
app:civ_shadowbooleanfalse
app:civ_shadow_colorcolorBLACK
app:civ_shadow_radiusdimension8dp
app:civ_shadow_gravitycenter, top, bottom, start or endbottom

ℹ️ You can also use android:elevation instead of app:civ_shadow to have default Material Design elevation.

KOTLIN

val circularImageView = findViewById<CircularImageView>(R.id.circularImageView)
circularImageView.apply {
    // Set Color
    circleColor = Color.WHITE
    // or with gradient
    circleColorStart = Color.BLACK
    circleColorEnd = Color.RED
    circleColorDirection = CircularImageView.GradientDirection.TOP_TO_BOTTOM

    // Set Border
    borderWidth = 10f
    borderColor = Color.BLACK
    // or with gradient
    borderColorStart = Color.BLACK
    borderColorEnd = Color.RED
    borderColorDirection = CircularImageView.GradientDirection.TOP_TO_BOTTOM
    
    // Add Shadow with default param
    shadowEnable = true
    // or with custom param
    shadowRadius = 7f
    shadowColor = Color.RED
    shadowGravity = CircularImageView.ShadowGravity.CENTER
}

JAVA

CircularImageView circularImageView = findViewById(R.id.circularImageView);
// Set Color
circularImageView.setCircleColor(Color.WHITE);
// or with gradient
circularImageView.setCircleColorStart(Color.BLACK);
circularImageView.setCircleColorEnd(Color.RED);
circularImageView.setCircleColorDirection(CircularImageView.GradientDirection.TOP_TO_BOTTOM);

// Set Border
circularImageView.setBorderWidth(10f);
circularImageView.setBorderColor(Color.BLACK);
// or with gradient
circularImageView.setBorderColorStart(Color.BLACK);
circularImageView.setBorderColorEnd(Color.RED);
circularImageView.setBorderColorDirection(CircularImageView.GradientDirection.TOP_TO_BOTTOM);

// Add Shadow with default param
circularImageView.setShadowEnable(true);
// or with custom param
circularImageView.setShadowRadius(7f);
circularImageView.setShadowColor(Color.RED);
circularImageView.setShadowGravity(CircularImageView.ShadowGravity.CENTER);

LIMITATIONS

  • By default the ScaleType is FIT_CENTER. You can also used CENTER_INSIDE AND CENTER_CROP.
  • Enabling adjustViewBounds is not supported as this requires an unsupported ScaleType.

SUPPORT ❤️

Find this library useful? Support it by joining stargazers for this repository ⭐️
And follow me for my next creations 👍

LICENCE

CircularImageView by Lopez Mikhael is licensed under a Apache License 2.0.

android
circularimageview

lopspower/CircularImageView

Create circular ImageView in Android in the simplest way possible

Kotlin

1,958

154 commits

updated Oct 11, 2022

See the code

README

CircularImageView

sample

Platform API Maven Central Twitter

This is an Android project allowing to realize a circular ImageView in the simplest way possible.

Android app on Google Play

USAGE

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.3.1'

XML

<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="10dp"
    app:civ_shadow_color="#3f51b5"/>

You must use the following properties in your XML to change your CircularImageView.

PropertiesTypeDefault
app:civ_circle_colorcolorWHITE
app:civ_circle_color_startcolorciv_circle_color
app:civ_circle_color_endcolorciv_circle_color
app:civ_color_directionleft_to_right, right_to_left, top_to_bottom or bottom_to_topleft_to_right
app:civ_borderbooleantrue
app:civ_border_widthdimension4dp
app:civ_border_colorcolorWHITE
app:civ_border_color_startcolorciv_border_color
app:civ_border_color_endcolorciv_border_color
app:civ_border_color_directionleft_to_right, right_to_left, top_to_bottom or bottom_to_topleft_to_right
app:civ_shadowbooleanfalse
app:civ_shadow_colorcolorBLACK
app:civ_shadow_radiusdimension8dp
app:civ_shadow_gravitycenter, top, bottom, start or endbottom

ℹ️ You can also use android:elevation instead of app:civ_shadow to have default Material Design elevation.

KOTLIN

val circularImageView = findViewById<CircularImageView>(R.id.circularImageView)
circularImageView.apply {
    // Set Color
    circleColor = Color.WHITE
    // or with gradient
    circleColorStart = Color.BLACK
    circleColorEnd = Color.RED
    circleColorDirection = CircularImageView.GradientDirection.TOP_TO_BOTTOM

    // Set Border
    borderWidth = 10f
    borderColor = Color.BLACK
    // or with gradient
    borderColorStart = Color.BLACK
    borderColorEnd = Color.RED
    borderColorDirection = CircularImageView.GradientDirection.TOP_TO_BOTTOM
    
    // Add Shadow with default param
    shadowEnable = true
    // or with custom param
    shadowRadius = 7f
    shadowColor = Color.RED
    shadowGravity = CircularImageView.ShadowGravity.CENTER
}

JAVA

CircularImageView circularImageView = findViewById(R.id.circularImageView);
// Set Color
circularImageView.setCircleColor(Color.WHITE);
// or with gradient
circularImageView.setCircleColorStart(Color.BLACK);
circularImageView.setCircleColorEnd(Color.RED);
circularImageView.setCircleColorDirection(CircularImageView.GradientDirection.TOP_TO_BOTTOM);

// Set Border
circularImageView.setBorderWidth(10f);
circularImageView.setBorderColor(Color.BLACK);
// or with gradient
circularImageView.setBorderColorStart(Color.BLACK);
circularImageView.setBorderColorEnd(Color.RED);
circularImageView.setBorderColorDirection(CircularImageView.GradientDirection.TOP_TO_BOTTOM);

// Add Shadow with default param
circularImageView.setShadowEnable(true);
// or with custom param
circularImageView.setShadowRadius(7f);
circularImageView.setShadowColor(Color.RED);
circularImageView.setShadowGravity(CircularImageView.ShadowGravity.CENTER);

LIMITATIONS

  • By default the ScaleType is FIT_CENTER. You can also used CENTER_INSIDE AND CENTER_CROP.
  • Enabling adjustViewBounds is not supported as this requires an unsupported ScaleType.

SUPPORT ❤️

Find this library useful? Support it by joining stargazers for this repository ⭐️
And follow me for my next creations 👍

LICENCE

CircularImageView by Lopez Mikhael is licensed under a Apache License 2.0.

android
circularimageview

Project health

Overall

1.9/10

Maintained

0/10

Code review

0/10
OpenSSF Scorecard

Latest release

4.3.1 · Aug 23, 2022

Releases this year

0

Significant stargazers

Joe Birch

2,266 followers · starred Dec 2014

Howard Edwards

19 followers · starred Aug 2016