有问题。在我设置为自定义视图的自定义行为类中。我跟踪回收器视图的移动并获取行为类方法中的所有偏移量。 onNestedScroll,onNestedPreScroll,然后改变我的视图大小。当我的视图被扩展并且我试图折叠它时,我在onNestedPreScroll方法中得到相反的dy值,如:40 -50 120 -130 300 -320等,但我只在一个方向上移动手指。 在网上搜索。没有找到任何东西。你能帮帮我吗?
class CustomFilterBehavior : CoordinatorLayout.Behavior<CustomFilterViewTabLayout> {
private var skipNestedPreScroll = false
constructor(context: Context) : this(context, null)
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
override fun onStartNestedScroll(coordinatorLayout: CoordinatorLayout,
child: CustomFilterViewTabLayout,
directTargetChild: View,
target: View?,
nestedScrollAxes: Int): Boolean {
return nestedScrollAxes and ViewCompat.SCROLL_AXIS_VERTICAL != 0
}
override fun onNestedScroll(coordinatorLayout: CoordinatorLayout?,
child: CustomFilterViewTabLayout?,
target: View?,
dxConsumed: Int,
dyConsumed: Int,
dxUnconsumed: Int,
dyUnconsumed: Int) {
if (dyUnconsumed < 0) {
child?.moveLayout(dyUnconsumed, false)
skipNestedPreScroll = true
} else {
skipNestedPreScroll = false
}
}
override fun onNestedPreScroll(coordinatorLayout: CoordinatorLayout?, child: CustomFilterViewTabLayout?, target: View?, dx: Int, dy: Int, consumed: IntArray?) {
if (dy != 0 && !skipNestedPreScroll) {
child?.let {
println(dy)
consumed?.set(1, it.moveLayout(dy, true))
}
}
}
override fun onStopNestedScroll(coordinatorLayout: CoordinatorLayout?,
child: CustomFilterViewTabLayout?,
target: View?) {
child?.stopScroll()
skipNestedPreScroll = false
super.onStopNestedScroll(coordinatorLayout, child, target)
}
}