Created
December 11, 2019 04:03
-
-
Save vinhdn/c62eb5ae95d07aff2b04d7076d9e37da to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context=".MainActivity"> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Đã trả được" | |
android:layout_marginBottom="40dp" | |
app:layout_constraintBottom_toBottomOf="parent" | |
app:layout_constraintLeft_toLeftOf="parent" | |
app:layout_constraintRight_toRightOf="parent" | |
app:layout_constraintTop_toTopOf="parent" /> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="40%" | |
android:layout_marginTop="40dp" | |
android:textSize="40sp" | |
android:textStyle="bold" | |
android:textColor="@color/colorPrimary" | |
app:layout_constraintBottom_toBottomOf="parent" | |
app:layout_constraintLeft_toLeftOf="parent" | |
app:layout_constraintRight_toRightOf="parent" | |
app:layout_constraintTop_toTopOf="parent" /> | |
<com.humaxdigital.progressbar.ProgressBarView | |
android:layout_width="300dp" | |
android:layout_height="300dp" | |
app:layout_constraintBottom_toBottomOf="parent" | |
app:layout_constraintLeft_toLeftOf="parent" | |
app:layout_constraintRight_toRightOf="parent" | |
app:layout_constraintTop_toTopOf="parent"/> | |
</androidx.constraintlayout.widget.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProgressBarView : View { | |
var paint: Paint = Paint() | |
constructor(context: Context) : this(context, null) | |
constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0) | |
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr){ | |
paint.style = Paint.Style.FILL | |
paint.color = Color.BLUE | |
} | |
override fun onDraw(canvas: Canvas) { | |
super.onDraw(canvas) | |
canvas.drawColor(Color.TRANSPARENT) | |
val h = 80f | |
val max = 24 | |
val process = 40 | |
for (i in 0..max) { | |
canvas.save() | |
val top = if(i % 6 == 0) 0f else 15f | |
val hi = if(i % 6 == 0) h + 30f else h | |
val degress = i * (360f / max) | |
canvas.rotate(degress, width / 2f, height / 2f) | |
if(degress / 3.6f > process) { | |
paint.color = Color.LTGRAY | |
} else { | |
paint.color = Color.BLUE | |
} | |
canvas.drawRect(width /2 - 10f, top, width/2 + 10f, hi, paint) | |
canvas.restore() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment