Код: Выделить всё
internal class V(context: Context?) : View(context) {
var path: Path = Path()
var paint: Paint = Paint(Paint.ANTI_ALIAS_FLAG)
var length: Float = 0f
var intervals: FloatArray = floatArrayOf(0f, 0f)
init {
paint.color = Color.GREEN
paint.style = Paint.Style.STROKE
paint.strokeWidth = 20f
}
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
path.reset()
val rect = RectF(0f, 0f, w.toFloat(), h.toFloat())
val inset = paint.strokeWidth
rect.inset(inset, inset)
path.addRoundRect(rect, 100f, 100f, Path.Direction.CW)
length = PathMeasure(path, false).length
intervals[1] = length
intervals[0] = intervals[1]
val effect: PathEffect = DashPathEffect(intervals, length)
paint.setPathEffect(effect)
}
fun setProgress(progress: Int) {
val effect: PathEffect = DashPathEffect(intervals, length - length * progress / 100)
paint.setPathEffect(effect)
invalidate()
}
override fun onDraw(canvas: Canvas) {
canvas.drawPath(path, paint)
}
}
Код: Выделить всё
val ll = LinearLayout(this)
ll.orientation = LinearLayout.VERTICAL
val sb = SeekBar(this)
ll.addView(sb)
val v = V(this)
ll.addView(v)
setContentView(ll)
val sbcl: SeekBar.OnSeekBarChangeListener = object : SeekBar.OnSeekBarChangeListener {
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
v.setProgress(progress)
}
override fun onStartTrackingTouch(seekBar: SeekBar) {}
override fun onStopTrackingTouch(seekBar: SeekBar) {}
}
sb.setOnSeekBarChangeListener(sbcl)
Подробнее здесь: https://stackoverflow.com/questions/784 ... ottom-left