可直接复制使用
1.自定义SignView
package com.myapplication.signaturecustomization
import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.Path
import android.util.AttributeSet
import android.view.MotionEvent
import android.view.View
import java.util.ArrayList
class SignView : View {
private var mPaint: Paint? = null
private var mPath: Path? = null
private var startX: Float = 0.toFloat()
private var startY: Float = 0.toFloat()
private var endX: Float = 0.toFloat()
private var endY: Float = 0.toFloat()
private var list: MutableList<SignModel>? = null
// private var mBoundAry: Rect? = null
private var bound: Int = 0
private val down = "down"
private val move = "move"
private val end = "end"
constructor(context: Context) : super(context) {
init()
}
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
init()
}
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
init()
}
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
}
/**
* 动态添加边框 暂时未用
*/
@SuppressLint("DrawAllocation")
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
super.onLayout(changed, left, top, right, bottom)
val width = width
val height = height
// mBoundAry = Rect(bound, bound, width - bound, height - bound)
}
override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)
drawLine(canvas)
}
@SuppressLint("ClickableViewAccessibility")
override fun onTouchEvent(event: MotionEvent): Boolean {
when (event.action) {
MotionEvent.ACTION_DOWN -> {
startX = event.x
startY = event.y
setData(list!!, event.x, event.y, down)
endX = event.x
endY = eve