=================
This is an Android project allowing to realize a circular and slice ImageView in the simplest way possible.
Slice ImageView like What's App avatar
This library was developed and extended based on https://github.com/lopspower/CircularImageView and rewrited by Kotlin
To make a circular and slice ImageView add CircleSliceImageView in your layout XML and add CircleSliceImageView library in your project or you can also grab it via Gradle:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.hantrungkien:CircleSliceImageView:v1.0.3'
}
<com.kienht.csiv.CircleSliceImageView
android:id="@+id/circleSliceImageView"
android:layout_width="200dp"
android:layout_height="200dp"
android:src="@drawable/logo" />
You must use the following properties in your XML to change your CircularImageView.
app:civ_mode
(integer) -> default = 0, slice = 1, border = 2app:civ_border_color
(color) -> default WHITEapp:civ_border_width
(dimension) -> default 4dpapp:civ_background_color
(color) -> default WHITEapp: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 bottomapp:civ_slice_sections
(integer) -> default 2app:civ_slice_border_width
(dimension) -> default 4dpapp:civ_slice_start_angle
(integer) -> default 0app:civ_slice_border_color
(color) -> default BLACKapp:civ_slice_random_color
(boolean) -> default falseapp:civ_slice_space_with_image
(boolean) -> default false
val circleSliceImageView = findViewById<CircleSliceImageView>(R.id.circleSliceImageView)
circleSliceImageView.mode = CircleSliceImageView.Mode.DEFAULT_MODE.getValue()
//Set slice
circleSliceImageView.mode = CircleSliceImageView.Mode.SLICE_MODE.getValue()
circleSliceImageView.sliceSections = 3
circleSliceImageView.setSliceBorderColor(resources.getColor(R.color.GrayLight))
circleSliceImageView.sliceBorderWidth = 10f
circleSliceImageView.sliceStartAngle = 90
circleSliceImageView.setBackgroundColor(Color.RED)
circleSliceImageView.isSliceRandomColor = true
circleSliceImageView.isSliceSpaceWithImage = true
//Set border
circleSliceImageView.mode = CircleSliceImageView.Mode.BORDER_MODE.getValue()
circleSliceImageView.setBorderColor(resources.getColor(R.color.GrayLight))
circleSliceImageView.borderWidth = 10f
circleSliceImageView.isShadowEnable = true
circleSliceImageView.addShadow()
circleSliceImageView.shadowRadius = 15f
circleSliceImageView.shadowColor = Color.RED
circleSliceImageView.setBackgroundColor(Color.RED)
circleSliceImageView.shadowGravity = CircleSliceImageView.ShadowGravity.CENTER
CircleSliceImageView circleSliceImageView = (CircleSliceImageView)findViewById(R.id.yourCircularImageView);
circleSliceImageView.setMode(CircleSliceImageView.Mode.DEFAULT_MODE)
//Set slice
circleSliceImageView.setMode(CircleSliceImageView.Mode.SLICE_MODE)
circleSliceImageView.setSliceSections(3);
circleSliceImageView.setSliceBorderColor(getResources().getColor(R.color.GrayLight));
circleSliceImageView.setSliceBorderWidth(10);
circleSliceImageView.setSliceStartAngle(90);
circleSliceImageView.setBackgroundColor(Color.RED);
circleSliceImageView.setSliceRandomColor(true);
circleSliceImageView.setSliceSpaceWithImage(true);
//Set border
circleSliceImageView.setMode(CircleSliceImageView.Mode.BORDER_MODE)
circleSliceImageView.setBorderColor(getResources().getColor(R.color.GrayLight));
circleSliceImageView.setBorderWidth(10);
circleSliceImageView.setShadowEnable(true)
circleSliceImageView.addShadow();
circleSliceImageView.setShadowRadius(15);
circleSliceImageView.setShadowColor(Color.RED);
circleSliceImageView.setBackgroundColor(Color.RED);
circleSliceImageView.setShadowGravity(CircleSliceImageView.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.
A special thanks go to Mr. Igalata
Copyright 2018 Kien Han Trung
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.