puzhibing
2026-08-21 5fa94b3718b4a78a4fcea4c97652b0ef20b7de3a
common/src/main/java/com/xw/common/custom/SlideButtonView.kt
@@ -56,6 +56,12 @@
    private var maxThumbX: Float = 0f
    private var isDragging = false
    private var slideThreshold: Float = 0.7f
    //是否能够使用
    var enable: Boolean = true
        set(value) {
            field = value
            invalidate()
        }
    private val scroller = Scroller(context, DecelerateInterpolator())
    private var onSlideCompleteListener: (() -> Unit)? = null
@@ -78,6 +84,7 @@
                thumbShape = getInt(R.styleable.SlideButtonView_thumbShape, SHAPE_ROUND_RECT)
                thumbCornerRadius = getDimension(R.styleable.SlideButtonView_thumbCornerRadius, 0f)
                slideThreshold = getFloat(R.styleable.SlideButtonView_slideThreshold, 0.7f)
                enable = getBoolean(R.styleable.SlideButtonView_enable, enable)
            } finally {
                recycle()
            }
@@ -213,6 +220,9 @@
    }
    override fun onTouchEvent(event: MotionEvent): Boolean {
        if (!enable) {
            return super.onTouchEvent(event)
        }
        when (event.action) {
            MotionEvent.ACTION_DOWN -> {
                val touchX = event.x