Issue
I am attaching the video how can achieve this please help me with this Thankyou In advance
Solution
Try ProgressBar
for showing Circular Progress Bar and CountDownTimer for timer:
Xml code:
<RelativeLayout
android:id="@+id/rlTimeOut"
android:layout_width="300dp"
android:layout_height="300dp">
<ProgressBar
android:id="@+id/progressTimeOut"
android:layout_width="300dp"
android:layout_height="300dp"
android:indeterminate="false"
android:progressDrawable="@drawable/bg_progress"
android:background="@drawable/circle_shape"
style="?android:attr/progressBarStyleHorizontal"
android:max="30"
android:progress="0" />
<TextView
android:id="@+id/tvTimeLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:layout_centerInParent="true"
android:textSize="25sp"
android:textColor="@color/black"/>
</RelativeLayout>
Drawable - bg_progress.xml
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="270"
android:toDegrees="270">
<shape
android:innerRadiusRatio="2.5"
android:shape="ring"
android:thickness="10dp"
android:useLevel="true">
<solid
android:angle="0"
android:color="@color/colorProgress1"
android:useLevel="false" />
</shape>
</rotate>
Drawable - circle_shape.xml
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="ring"
android:innerRadiusRatio="2.5"
android:thickness="10dp"
android:useLevel="false">
<solid android:color="#EFEFEF" />
</shape>
Add code in Kotlin Class
private lateinit var textViewTimer: CountDownTimer
private lateinit var progressBarTimer: CountDownTimer
fun setTimer() {
val maxCounter: Long = 4000
val diff: Long = 1000
textViewTimer = object : CountDownTimer(maxCounter, diff) {
override fun onTick(millisUntilFinished: Long) {
val diff = maxCounter - millisUntilFinished
tvTimeLeft.text = "" + millisUntilFinished / 1000
Log.i("Timer--", "onTick: differance: $diff")
}
override fun onFinish() {
//progressTimeOut.progress = 3
tvTimeLeft.text = "TIME UP!"
textViewTimer.cancel()
}
}.start()
val diff1: Long = 100
progressBarTimer = object : CountDownTimer(maxCounter, diff1) {
override fun onTick(millisUntilFinished: Long) {
val diff = maxCounter - millisUntilFinished
progressTimeOut.progress = diff.toInt() / 100
}
override fun onFinish() {
progressTimeOut.progress = 30
progressBarTimer.cancel()
}
}.start()
}
Answered By - Android Geek
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.