我试图在滚动视图到达 scrollY 位置时停止滚动。然后,当子视图(recyclerview)到达顶部或过度滚动时,将其更改回可滚动。
我尝试了两种方法
- onTouchListener - 它不与 scrollY 位置交互
nestedScrollView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
return false;
}
});
- setOnScrollChangeListener - 不知道如何将其设置为不可滚动
nestedScrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
@Override
public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
if (scrollY >400dp) {
}
}
编辑 1 个 XML
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<Linearlayout
android:layout_width="match_parent"
android:layout_height="match_parent">
//include more contents card
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:nestedScrollingEnabled="true"
android:orientation="vertical"
/>
</LinearLayout>
</androidx.core.widget.NestedScrollView>