[英]How to get ACTION_UP Touch Event for NestedScrollview
我想單擊父視圖 (LinearLayout) 偵聽器,但由於 NestedScrollView(Child) 而無法單擊。 所以我試圖 OnTouch NestedScrollView 但我只得到 ACTION_MOVE 但我需要 ACTION_UP 或 ACTION_DOWN 事件來執行功能
我嘗試通過創建自定義 NestedScrollView 和 Override OnInterceptTouch 事件和 requestDisallow(false)
xml
nestedScrollView?.setOnTouchListener { v, event ->
when (event.action) {
MotionEvent.ACTION_UP -> {
if (bind?.mainViewModel?.buttonTappedToCheckForRestriction?.value != false && bind?.mainViewModel?.visbility?.value != false) {
bind?.mainViewModel?.buttonTappedToCheckForRestriction?.postValue(true)
} else if (bind?.mainViewModel?.visbility?.value == true) {
bind?.mainViewModel?.buttonTappedToCheckForRestriction?.postValue(true)
}
}
}
return@setOnTouchListener false
};
要識別操作 NeedScrollView 的用戶,您應該忽略此功能
scroller.setOnScrollChangeListener(object : NestedScrollView.OnScrollChangeListener{
@Override
public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
if (scrollY > oldScrollY) {
Log.i(TAG, "Scroll DOWN");
}
if (scrollY < oldScrollY) {
Log.i(TAG, "Scroll UP");
}
if (scrollY == 0) {
Log.i(TAG, "TOP SCROLL");
}
if (scrollY == ( v.getMeasuredHeight() - v.getChildAt(0).getMeasuredHeight() )) {
Log.i(TAG, "BOTTOM SCROLL");
}
}
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.