首页 > 解决方案 > 滚动ScrollView android上的显示和隐藏按钮

问题描述

我有一个nested scrollview和一个button。我想在滚动时隐藏按钮,并在滚动停止时scrollview显示,无论向上滚动和向下滚动。button有人请帮忙。

标签: androidscrollandroid-nestedscrollview

解决方案


最后我找到了解决方案。

scrollView.setOnTouchListener(object : View.OnTouchListener {
            override fun onTouch(p0: View?, p1: MotionEvent?): Boolean {
                when (p1!!.getAction()) {
                    MotionEvent.ACTION_SCROLL, MotionEvent.ACTION_MOVE -> {
                        closeCaseButton.visibility = View.INVISIBLE
                    }
                    MotionEvent.ACTION_CANCEL, MotionEvent.ACTION_UP -> {
                        closeCaseButton.visibility = View.VISIBLE
                    }
                }
                return false
            }
        })

推荐阅读