自定义ProgressBar,包括:直线进度条
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.shenbengit:ProgressView:Tag'
}
LineProgressView
布局事例
<com.shencoder.progressview.LineProgressView
android:id="@+id/lpv2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:lpv_progress="0"
app:lpv_max="100"
app:lpv_line_reached_color="#2BB4FF"
app:lpv_line_unreached_color="#C9C9C9"
app:lpv_line_height="5dp"
app:lpv_line_corner_used="true|false"
app:lpv_progress_text_visibility="true|false"
app:lpv_progress_text_size="12sp"
app:lpv_progress_text_color="#2BB4FF"
app:lpv_progress_text_prefix=""
app:lpv_progress_text_suffix="%" />
代码事例
val lpv: LineProgressView = findViewById(R.id.lpv)
lpv.setProgress(progress: Int)//设置当前进度
lpv.setMaxProgress(maxProgress: Int)//设置最大进度
lpv.setLineReachedColor(color: Int)//进度条进度部分显示的颜色
lpv.setLineUnreachedColor(color: Int)//进度条剩余部分显示的颜色
lpv.setLineHeight(height: Int)//进度条线的高度
lpv.setLineCornerUsed(lineCornerUsed: Boolean)//true:带圆角,false:不带圆角
lpv.setProgressTextVisibility(isVisible: Boolean)//true:显示进度条上文字,false:不显示进度条上文字
lpv.setProgressTextSize(textSize: Int)//文字textSize
lpv.setProgressTextTypeface(typeface: Typeface?)
lpv.setProgressTextColor(textColor: Int)//文字textSize
lpv.setProgressTextPrefix(prefix: String?)//文字前缀
lpv.setProgressTextSuffix(suffix: String?)//文字后缀
lpv.getReachedPaint()//获取画笔
lpv.getUnreachedPaint()//获取画笔
lpv.getTextPaint()//获取画笔
lpv.setProgressWithAnimation(progress: Int, duration: Long, timeInterpolator: TimeInterpolator?)//通过动画的方式设置进度
lpv.cancelProgressAnimation()
lpv.resumeProgressAnimation()
lpv.pauseProgressAnimation()
lpv.isProgressAnimatorRunning()
lpv.isProgressAnimatorPaused()
//添加进度回调监听
lpv.setOnProgressListener(object : OnProgressListener {
override fun onProgressChanged(current: Int, max: Int, percentage: Int) {
}
})
//如果使用Kotlin
lpv1.setOnProgressListener { current, max, percentage ->
}