进度条优化
This commit is contained in:
parent
a2b8a6700a
commit
ea4cd36ffb
|
|
@ -28,6 +28,11 @@ class BenefitTaskItemView @JvmOverloads constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
with(mBinding.progressBar) {
|
||||||
|
setMax(100)
|
||||||
|
setProgress(0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setActionFun(action: ()->Unit) {
|
fun setActionFun(action: ()->Unit) {
|
||||||
|
|
|
||||||
|
|
@ -2,18 +2,20 @@ package com.ama.core.architecture.widget
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.Canvas
|
import android.graphics.Canvas
|
||||||
import android.graphics.Color
|
|
||||||
import android.graphics.Paint
|
import android.graphics.Paint
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import androidx.core.graphics.withSave
|
||||||
|
import com.ama.core.architecture.R
|
||||||
|
import com.ama.core.architecture.util.ResUtil
|
||||||
|
|
||||||
class CustomProgressBar(context: Context, attrs: AttributeSet) : View(context, attrs) {
|
class CustomProgressBar(context: Context, attrs: AttributeSet) : View(context, attrs) {
|
||||||
|
|
||||||
private var progress = 0
|
private var progress = 0
|
||||||
private var max = 100
|
private var max = 100
|
||||||
|
|
||||||
private val grayColor = Color.parseColor("#1affffff")
|
private var mBgColor = ResUtil.getColor(R.color.gray_d3)
|
||||||
private val greenColor = Color.parseColor("#ff00ff09")
|
private var mForColor = ResUtil.getColor(R.color.green_09)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -26,13 +28,16 @@ class CustomProgressBar(context: Context, attrs: AttributeSet) : View(context, a
|
||||||
val width = measuredWidth.toFloat()
|
val width = measuredWidth.toFloat()
|
||||||
val height = measuredHeight.toFloat()
|
val height = measuredHeight.toFloat()
|
||||||
|
|
||||||
paint.color = grayColor
|
|
||||||
canvas.drawRoundRect(0f, 0f, width, height, width/2, 0F, paint)
|
|
||||||
|
|
||||||
val progressWidth = (width) * progress / max
|
|
||||||
if (progressWidth > 0) {
|
canvas.withSave {
|
||||||
paint.color = greenColor
|
paint.color = mBgColor
|
||||||
canvas.drawRoundRect(0f, 0f, progressWidth, height, width/2, 0F, paint)
|
canvas.drawRoundRect(0f, 0f, width, height, height/2, height/2, paint)
|
||||||
|
val completeProgressWidth = (width) * progress / max
|
||||||
|
if (completeProgressWidth > 0) {
|
||||||
|
paint.color = mForColor
|
||||||
|
canvas.drawRoundRect(0f, 0f, completeProgressWidth, height, height/2, height/2, paint)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -46,4 +51,10 @@ class CustomProgressBar(context: Context, attrs: AttributeSet) : View(context, a
|
||||||
this.max = max
|
this.max = max
|
||||||
invalidate()
|
invalidate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun setBarColor(bgColor: Int=R.color.gray_d3, forColor: Int=R.color.green_09) {
|
||||||
|
mBgColor = ResUtil.getColor(bgColor)
|
||||||
|
mForColor = ResUtil.getColor(forColor)
|
||||||
|
invalidate()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -53,6 +53,8 @@
|
||||||
<color name="white">#FFFFFF</color>
|
<color name="white">#FFFFFF</color>
|
||||||
<color name="gray_3">#333333</color>
|
<color name="gray_3">#333333</color>
|
||||||
<color name="gray_9">#999999</color>
|
<color name="gray_9">#999999</color>
|
||||||
|
<color name="gray_d3">#FFE2D9D3</color>
|
||||||
|
<color name="green_09">#ff00ff09</color>
|
||||||
|
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
Loading…
Reference in New Issue