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
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
相關(guān)閱讀更多精彩內(nèi)容
- 2020-03-18當(dāng)時(shí)直播時(shí),看了一些內(nèi)容。繼續(xù)學(xué)習(xí)之。We have a simple message for...
- 切換到test目錄,執(zhí)行如下命令npm install chromedriver --chromedriver_c...
- 幫助文檔在這里 非常簡(jiǎn)單,這些scipy的方法能夠非常魯棒地直接應(yīng)用于dataframe的列中,只要你索引好了就行...
- 關(guān)于這個(gè)文章,感覺東西好像做得還不錯(cuò),但看起來(lái)有點(diǎn)費(fèi)力,文字好多,幫助解釋的圖表比較少。加之自己本來(lái)對(duì)測(cè)試了解非常...
- 我是黑夜里大雨紛飛的人啊 1 “又到一年六月,有人笑有人哭,有人歡樂(lè)有人憂愁,有人驚喜有人失落,有的覺得收獲滿滿有...