效果图:
控件组成:外圆环、渐变进度条、进度跟随小圆、中间log
直接上源码:
import android.animation.ArgbEvaluator
import android.animation.ValueAnimator
import android.content.Context
import android.graphics.*
import android.graphics.drawable.Drawable
import android.util.AttributeSet
import android.util.Log
import android.view.View
import com.hisense.aifitness.R
import com.hisense.aifitness.utils.PixeUtils
import java.math.BigDecimal
import kotlin.math.PI
import kotlin.math.cos
import kotlin.math.sin
class RoundProgressBar : View {
private var mBitmap: Bitmap? = null
private val TAG = "RoundProgressBar"
private var paint: Paint
//外层圆环颜色
private var outerCircleColor: Int
//内层圆环颜色(可纯色,可渐变)
private var progressCircleColor: Int
private var smallCircleColor: Int
private var progressStartColor: Int
private var progressEndColor: Int
private var circleWidth: Float
private var maxProgress: Float
//小圆距离进度条距离
private val SPACE = 3
private var currentProgress: Float = 0f
private var progressArgbColor: Boolean
//是否支持前面的小圆
private var smallCircleEnable: Boolean
private var center: Float = 0.0f
private var outerCircleRadius: Float = 0.0f
private var mArgbEvaluator: ArgbEvaluator
private var animationDuration: Long = 0
private var centerDrawableId: Int
constructor(context: Context) : this(context, null)
constructor(context: Context, attributeSet: AttributeSet