From 18fa7ac2dec93a37169b54f4c81deb380d286bed Mon Sep 17 00:00:00 2001 From: jhengazuki Date: Fri, 15 Aug 2025 13:33:39 +0800 Subject: [PATCH] Optimize scroll --- .../com/fongmi/android/tv/ui/custom/CustomRecyclerView.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/fongmi/android/tv/ui/custom/CustomRecyclerView.java b/app/src/main/java/com/fongmi/android/tv/ui/custom/CustomRecyclerView.java index 1eab8edf4..fe354a33e 100644 --- a/app/src/main/java/com/fongmi/android/tv/ui/custom/CustomRecyclerView.java +++ b/app/src/main/java/com/fongmi/android/tv/ui/custom/CustomRecyclerView.java @@ -5,6 +5,7 @@ import android.content.res.TypedArray; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.View; +import android.view.ViewConfiguration; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -16,6 +17,7 @@ import com.fongmi.android.tv.utils.ResUtil; public class CustomRecyclerView extends RecyclerView { private int maxHeight; + private int touchSlop; private float x1; private float y1; @@ -40,6 +42,7 @@ public class CustomRecyclerView extends RecyclerView { private void init(Context context, AttributeSet attrs) { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CustomRecyclerView); maxHeight = a.getLayoutDimension(R.styleable.CustomRecyclerView_maxHeight, maxHeight); + touchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); setOverScrollMode(View.OVER_SCROLL_NEVER); a.recycle(); } @@ -84,7 +87,7 @@ public class CustomRecyclerView extends RecyclerView { float y2 = event.getY(); float offsetX = Math.abs(x2 - x1); float offsetY = Math.abs(y2 - y1); - if (Math.abs(offsetX) > Math.abs(offsetY)) getParent().requestDisallowInterceptTouchEvent(false); + if (offsetX > offsetY && offsetX > touchSlop) getParent().requestDisallowInterceptTouchEvent(false); break; } return super.dispatchTouchEvent(event);