添加onItemTouchListener后添加平滑滚动

时间:2019-07-23 14:34:36

标签: android android-recyclerview

我想在recyclerview中禁用垂直滚动(因为它在nestedscrollview中并且没有“正常”行为)。但是在添加onInterceptTouchEvent之后,我的recyclerview无法“平滑地”滚动(我的意思是,我无法滚动不可见的事件,只能滚动当前的可见事件)。该如何解决?

    specialDiscountsCategoriesList.layoutManager = LinearLayoutManager(activity, LinearLayoutManager.HORIZONTAL, false)
    specialDiscountsCategoriesList.isNestedScrollingEnabled = false
    specialDiscountsCategoriesList.setHasFixedSize(false)

    specialDiscountsCategoriesList.addOnItemTouchListener(object : RecyclerView.OnItemTouchListener {
        override fun onTouchEvent(rv: RecyclerView?, e: MotionEvent?) {

        }

        override fun onInterceptTouchEvent(rv: RecyclerView?, e: MotionEvent?): Boolean {
            when (e?.action) {
                MotionEvent.ACTION_UP, MotionEvent.ACTION_DOWN -> {
                    specialDiscountsCategoriesList.requestDisallowInterceptTouchEvent(false)
                    return true
                }
            }

            return false
        }

        override fun onRequestDisallowInterceptTouchEvent(disallowIntercept: Boolean) {

        }

0 个答案:

没有答案