在 NestedScrollView 中查看不可滚动无法移动到顶部或底部

View not scrollable inside NestedScrollView cant get movement to top or bottom

具有以下结构:

<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"    
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/nestedScrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <AppGridView
            android:id="@+id/appGridView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

    </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>

我的 AppGridView 位于 NestedScrollView 内,需要使用 onTouchEvent 方法来捕捉动作,但是当它位于 NestedScrollView 内时,AppGridView 的 onTouchEvent 是:

1) Only called when the is ACTION_DOWN or ACTION_MOVE to left or right
2) When is ACTION_MOVE to top or bottom, it's never called
3) if only ACTION_DOWN or ACTION_DOWN + ACTION_MOVE to the sides, then it calls ACTION_UP

我已经尝试使用此方法禁用 nestedScrollView(在 AppGridView class 中,在 ACTION_DOWN onTouch 上调用,然后在 ACTION_UP 上调用),但无法正常工作:

private void onTouchStarted() {
    nestedScrollView.startNestedScroll(ViewCompat.SCROLL_AXIS_HORIZONTAL| ViewCompat.SCROLL_AXIS_VERTICAL);

}

private void onTouchEnd() {
    nestedScrollView.stopNestedScroll();
}

我还需要将其插入 activity 以结束 AppGridView 正在保存的移动...

nestedScrollView.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_UP) {
            appGridView.actionMoveUp();
        }
        return false;
    }
});

有什么方法可以禁用 NestedScrollView 的滚动吗?或者也许删除所有可以聚焦的方式...

我在 google 上为此搜索了很多,但有日期选项 "last year",有一次我在没有它的情况下搜索并找到了这个博客 post:https://mobiarch.wordpress.com/2013/11/21/prevent-touch-event-theft-in-android/

在此之后,我只是改变了

private void onTouchStarted() {
    nestedScrollView.startNestedScroll(ViewCompat.SCROLL_AXIS_HORIZONTAL| ViewCompat.SCROLL_AXIS_VERTICAL);
}

private void onTouchEnd() {
    nestedScrollView.stopNestedScroll();
}

对此:

private void startTouch() {
    nestedScrollView.requestDisallowInterceptTouchEvent(true);
}

private void endTouch() {
    nestedScrollView.requestDisallowInterceptTouchEvent(false);
}

效果很好