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 11ea1f5f3..d6189630d 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 @@ -3,6 +3,7 @@ package com.fongmi.android.tv.ui.custom; import android.content.Context; import android.content.res.TypedArray; import android.util.AttributeSet; +import android.view.MotionEvent; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -13,6 +14,8 @@ import com.fongmi.android.tv.R; public class CustomRecyclerView extends RecyclerView { private int maxHeight; + private float x1; + private float y1; public CustomRecyclerView(@NonNull Context context) { super(context); @@ -39,6 +42,12 @@ public class CustomRecyclerView extends RecyclerView { if (holder != null) holder.itemView.requestFocus(); } + private int getNewSpec(int heightMeasureSpec) { + int newHeight = MeasureSpec.makeMeasureSpec(maxHeight, MeasureSpec.AT_MOST); + if (heightMeasureSpec > newHeight) heightMeasureSpec = newHeight; + return heightMeasureSpec; + } + @Override public void scrollToPosition(int position) { super.scrollToPosition(position); @@ -47,8 +56,28 @@ public class CustomRecyclerView extends RecyclerView { @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - int newHeight = MeasureSpec.makeMeasureSpec(maxHeight, MeasureSpec.AT_MOST); - if (heightMeasureSpec > newHeight) heightMeasureSpec = newHeight; + if (maxHeight != 0) heightMeasureSpec = getNewSpec(heightMeasureSpec); super.onMeasure(widthMeasureSpec, heightMeasureSpec); } + + @Override + public boolean dispatchTouchEvent(MotionEvent event) { + switch (event.getAction()) { + case MotionEvent.ACTION_UP: + x1 = y1 = 0; + break; + case MotionEvent.ACTION_DOWN: + x1 = event.getX(); + y1 = event.getY(); + break; + case MotionEvent.ACTION_MOVE: + float x2 = event.getX(); + 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); + break; + } + return super.dispatchTouchEvent(event); + } } diff --git a/app/src/mobile/res/layout/fragment_type.xml b/app/src/mobile/res/layout/fragment_type.xml index dd6cf6fcf..1c4142fb0 100644 --- a/app/src/mobile/res/layout/fragment_type.xml +++ b/app/src/mobile/res/layout/fragment_type.xml @@ -9,7 +9,7 @@ android:layout_width="match_parent" android:layout_height="match_parent"> -