scrollY の位置に達したら、scrollview のスクロールを停止しようとしています。次に、子ビュー (recyclerview) が上部に到達するかオーバースクロールしたときに、スクロール可能に戻します。
2つの方法を試しました
- 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>