自定义ScrollView实现ScrollView不惯性滑动
class NoFlyingScrollView(context:Context, attr: AttributeSet):ScrollView(context,attr){ override fun fling(velocityY: Int) {// super.fling(0) }}复制代码
Touch事件监听
scroll.setOnTouchListener({v,event-> when(event.action){ MotionEvent.ACTION_CANCEL, MotionEvent.ACTION_UP -> { Log.d("--->","scroll.height="+scroll.height+" event.rawY="+event.rawY+" top.height="+top.height+" scroll.scrollY"+scroll.scrollY+" top.scrollY="+top.scrollY) if(showingTop){//正在展示顶部 if(scroll.height+scroll.scrollY top.height&&scroll.height+scroll.scrollY top.height+spaceDistance){ scroll.smoothScrollTo(0,top.height) showingTop = false return@setOnTouchListener true } }else{//正在展示下面的view //滚动高度小于topview-安全距离 if (scroll.scrollY top.height-spaceDistance&&scroll.scrollY top.height){ showingTop = false return@setOnTouchListener false } } } MotionEvent.ACTION_MOVE->{ } } false })复制代码