Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.hantrungkien:CircleSliceImageView:v1.0.3'
}
dependencies {
implementation("com.github.hantrungkien:CircleSliceImageView:v1.0.3")
}
<dependency>
<groupId>com.github.hantrungkien</groupId>
<artifactId>CircleSliceImageView</artifactId>
<version>v1.0.3</version>
</dependency>
libraryDependencies += "com.github.hantrungkien" % "CircleSliceImageView" % "v1.0.3"
:dependencies [[com.github.hantrungkien/CircleSliceImageView "v1.0.3"]]
=================
<img src="preview.gif" alt="sample" title="sample" width="300" height="435" align="right" vspace="52" />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'
}
<img src="slice.png" alt="slice" title="slice" width="320" height="640" align="middle"/>
<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 falseval 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);
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.