class DevCircleView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr) {
private val sweepAngle = 10f
private var radius = 0
private val paint = Paint(ANTI_ALIAS_FLAG)
private val paintFrame = Paint(ANTI_ALIAS_FLAG)
private val pointCenter = Point()
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
super.onSizeChanged(w, h, oldw, oldh)
val paddingH = paddingLeft + paddingRight
val paddingV = paddingTop + paddingBottom
val width = w - paddingH
val height = h - paddingV
radius = width.coerceAtMost(height) / 2
pointCenter.x = paddingH / 2 + radius
pointCenter.y = paddingV / 2 + radius
}
override fun onDraw(canvas: Canvas) {
drawCircle(canvas)
drawArc(canvas)
}
private fun drawArc(canvas: Canvas) {
paintFrame.color = Color.BLACK
paintFrame.style = Paint.Style.STROKE
paintFrame.strokeWidth = 6f * Resources.getSystem().displayMetrics.density
paintFrame.strokeCap = Paint.Cap.ROUND
pointCenter.x.toFloat()
canvas.drawArc(
RectF(
(pointCenter.x - radius).toFloat(), (pointCenter.y - radius).toFloat(),
(pointCenter.x + radius).toFloat(), (pointCenter.y + radius).toFloat()
),
-(sweepAngle / 2 + 90f) + offsetAngle, sweepAngle + offsetSweepAngle, false, paintFrame
)
}
private fun drawCircle(canvas: Canvas) {
paint.color = 0xFFEEEEEE.toInt()
paint.style = Paint.Style.FILL_AND_STROKE
paint.strokeWidth = 6f * Resources.getSystem().displayMetrics.density
canvas.drawCircle(pointCenter.x.toFloat(), pointCenter.y.toFloat(), radius.toFloat(), paint)
}
private val animator = ValueAnimator.ofInt(0, 360)
init {
initAnimate()
}
private var offsetAngle = 0
private var offsetSweepAngle = 0
private fun initAnimate() {
animator.apply {
duration = 1200
repeatMode = RESTART
repeatCount = -1
interpolator = LinearInterpolator()
addUpdateListener {
offsetAngle = it.animatedValue as Int
if (offsetAngle <= 180) {
offsetSweepAngle = offsetAngle / 3
} else {
offsetSweepAngle = (360 - offsetAngle) / 3
}
invalidate()
}
}
}
fun startAnimate() {
animator.start()
}
}
test
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 2020-03-18当时直播时,看了一些内容。继续学习之。We have a simple message for...
- 切换到test目录,执行如下命令npm install chromedriver --chromedriver_c...
- 帮助文档在这里 非常简单,这些scipy的方法能够非常鲁棒地直接应用于dataframe的列中,只要你索引好了就行...
- 关于这个文章,感觉东西好像做得还不错,但看起来有点费力,文字好多,帮助解释的图表比较少。加之自己本来对测试了解非常...