In this article, we will learn about how to add Croller in android. Croller is used to implement circular Seekbar in android. Seekbar is a type of progress bar. We can drag the seekbar from left to right and vice versa and hence changes the current progress. This is how a Croller look like.
Table of Attributes
XML Attribute
Java set method
Functionality
anticlockwise
setAntiClockwise(boolean anticlockwise)
Set the direction of rotation
progress
setProgress(int progress)
Set the current progress of the seekbar
label
setLabel(String str)
Set the label
label_size
setLabelSize(int size)
Set the label size
label_color
setLabelColor(int color)
Set the label color
is_continuous
setIsContinuous(boolean bool)
Set whether seekbar is conitnuous or discrete
max
setMax(int max)
Set the maximum value of the seekbar
min
setMin(int min)
Set the minimum value of the seekbar (Default is 1)
start_offset
setStartOffset(int offset)
Set the seekbar start offset angle from bottom horizontal center
sweep_angle
setSweepAngle(int angle)
Set the total angle covered by the seekbar
progress_primary_stroke_width
setProgressPrimaryStrokeWidth(float width)
Set the primary progress thickness for continuous type
progress_secondary_stroke_width
setProgressSecondaryStrokeWidth(float width)
Set the secondary progress thickness for continuous type
progress_primary_circle_size
setProgressPrimaryCircleSize(float size)
Set the primary progress circle size for discrete type
progress_secondary_circle_size
setProgressSecondaryCircleSize(float size)
Set the secondary progress circle size for discrete type
indicator_width
setIndicatorWidth(float width)
Set the progress indicator width
indicator_color
setIndicatorColor(int color)
Set the progress indicator color
progress_primary_color
setProgressPrimaryColor(int color)
Set the progress primary(active) color
progress_secondary_color
setProgressSecondaryColor(int color)
Set the progress secondary(inactive) color
progress_radius
setProgressRadius(float radius)
Set the radius of the progress arc
main_circle_radius
setMainCircleRadius(float radius)
Set the main(front) circle radius
back_circle_radius
setBackCircleRadius(float radius)
Set the back circle radius
main_circle_color
setMainCircleColor(int color)
Set the main(front) circle color
back_circle_color
setBackCircleColor(int color)
Set the back circle color
Getting Started
Step 1: Add the support Library in build.gradle file and add dependency in the dependencies section.
implementation 'com.sdsmdg.harjot:croller:1.0.7'
Step 2: Add the following code in activity_main.xml file. In this file we add our Croller to the layout.
activity_main.xml
Step 3: Add the following code in MainActivity.java file. In this we add setOnCrollerChangeListener() to our croller so whenever there is a change in progress setOnCrollerChangeListener() get invoked automatically.
MainActivity.xml
packageorg.geeksforgeeks.crollerimportandroidx.appcompat.app.AppCompatActivity;importandroid.os.Bundle;importandroid.widget.Toast;importcom.sdsmdg.harjot.crollerTest.Croller;importcom.sdsmdg.harjot.crollerTest.OnCrollerChangeListener;publicclassMainActivityextendsAppCompatActivity{@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Crollercroller=findViewById(R.id.croller);// when there is a change in the progress of croller// this function get invoked automaticallycroller.setOnCrollerChangeListener(newOnCrollerChangeListener(){@OverridepublicvoidonProgressChanged(Crollercroller,intprogress){}// when the user is starting to change the progress// this function gets invoked automatically.@OverridepublicvoidonStartTrackingTouch(Crollercroller){Toast.makeText(MainActivity.this,"Start",Toast.LENGTH_SHORT).show();}// when the user stops to change the progress// this function gets invoked automatically.@OverridepublicvoidonStopTrackingTouch(Crollercroller){Toast.makeText(MainActivity.this,"Stop",Toast.LENGTH_SHORT).show();}});}}
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.