实现后效果:由于是在模拟器上跑的背面的封面列表加载不出来,实际效果请真机运行
image.png
具体代码如下:
绘制上层滑动控件部分
package com.cj.customwidget.widget
import android.content.Context
import android.graphics.*
import android.util.AttributeSet
import android.view.MotionEvent
import android.view.View
import com.cj.customwidget.R
import com.cj.customwidget.p
/**
* @package com.cj.customwidget.widget
* @author luan
* @date 2020/10/16
* @des 视频裁剪区域选择
*/
class CropSeekBar : View {
constructor(context: Context) : super(context) {
initView(context, null)
}
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
initView(context, attrs)
}
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
initView(context, attrs)
}
private val color = Color.WHITE//边框颜色
var slideW = 20f//两侧滑块宽度
var strokeW = 4f//上下边框宽度
var slideOutH = 10f//进度滑块越界高度
var midSlideW = 8f//中间滑块宽度
private var radio = 16f//圆角角度
val slidePadding = 100//两侧滑块外边距
var midProgress = 0f//中间滑块的x坐标
var seekLeft = 0f//左测滑块的x坐标
var seekRight = 0f//右测滑块的x坐标
var maxInterval = 60L * 1000//最大区间-时长ms
var minInterval = 10L * 1000//最小区间-时长ms
private val strokeLinePaint = Paint()
private val slidePaint = Paint()
private val path = Path()
private val progressRectF = RectF()//中间滑块有效触摸范围
private val leftSlideTouchRectF = RectF()//左滑块有效触摸范围
private val rightSlideTouchRectF = RectF()//右滑块有效触摸范围
private var isMoveSlide: Boolean = false
var onChangeProgress: (progress: Float) -> Unit = { progress -> }
var onSectionChange: (left: Float, right: Float) -> Unit = { left, right -> }
// var onTouchChange: (isTouch: Boolean) -> Unit = {}
private fun initView(context: Context, attrs: AttributeSet?) {
setWillNotDraw(false)
attrs?.apply {
val obtain = context.obtainStyledAttributes(attrs, R.styleable.CropSeekBar)
slideOutH = obtain.getDimension(R.styleable.CropSeekBar_vc_slide_out_h, slideOutH)
radio = obtain.getDimension(R.styleable.CropSeekBar_vc_radio, radio)
obtain.recycle()
}
strokeLinePaint.isAntiAlias = true
strokeLinePaint.strokeWidth = strokeW
strokeLinePaint.color = color
strokeLinePaint.strokeWidth = strokeW
slidePaint.isAntiAlias = true
slidePaint.color = color
slidePaint.style = Paint.Style.FILL
}
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
seekLeft = slidePadding.toFloat() + slideW / 2
seekRight = width - slidePadding.toFloat() - slideW / 2
midProgress = slidePadding.toFloat() + slideW + midSlideW / 2
super.onLayout(changed, left, top, right,