由于没有答案被张贴,我找到了解决这些我张贴的溶液作为这个问题的答案。
所以,这里是我做了什么。
我已经采取了两个recyclerViews
现在已经采取了两个变量保持最后滚动的轨道,创造了设置rvCategoryList高度的方法
var lastY: Int = 0
var counter = 0
private fun setCategoryViewHeight(dy: Int) {
val params = rvCategoryList.layoutParams
if ((dy > 0 && lastY >= 0) || (dy < 0 && lastY <= 0)) {
counter = 0
params.height = params.height - dy
if (dy > 0) {
if (params.height < rvHeight / 1.7) {
params.height = (rvHeight / 1.7).toInt()
}
} else {
if (params.height > rvHeight) {
params.height = rvHeight
}
}
rvCategoryList.layoutParams = params
lastY = dy
} else {
counter++
if (counter > 2) {
counter = 0
lastY = 0
}
}
}
并且对如下的rvItemList应用OnScrollListener。
rvItemList.clearOnScrollListeners()
rvItemList.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
lastY = 0 //As the scroll state has been changed reinitializing the lastY variable.
}
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)
setCategoryViewHeight(dy) //Setting height everytime.
}
})
我希望这会帮助别人谁想要创建一个类似的观点。