修复上下滑动会导致左右切换问题,添加了新的自定义组件RecyclerViewAtViewPager2

pull/1006/head
gongym 4 years ago
parent 6e69efb34e
commit ba37b48969
  1. 55
      app/src/main/java/io/legado/app/ui/widget/RecyclerViewAtViewPager2.java
  2. 2
      app/src/main/res/layout/fragment_books.xml
  3. 2
      app/src/main/res/layout/fragment_explore.xml
  4. 2
      app/src/main/res/layout/fragment_rss.xml
  5. 2
      app/src/main/res/layout/fragment_rss_articles.xml

@ -0,0 +1,55 @@
package io.legado.app.ui.widget;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;
public class RecyclerViewAtViewPager2 extends RecyclerView {
public RecyclerViewAtViewPager2(@NonNull Context context) {
super(context);
}
public RecyclerViewAtViewPager2(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public RecyclerViewAtViewPager2(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
private int startX, startY;
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
startX = (int) ev.getX();
startY = (int) ev.getY();
getParent().requestDisallowInterceptTouchEvent(true);
break;
case MotionEvent.ACTION_MOVE:
int endX = (int) ev.getX();
int endY = (int) ev.getY();
int disX = Math.abs(endX - startX);
int disY = Math.abs(endY - startY);
if (disX > disY) {
if (disX > 50) {
getParent().requestDisallowInterceptTouchEvent(false);
}
} else {
getParent().requestDisallowInterceptTouchEvent(true);
}
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
getParent().requestDisallowInterceptTouchEvent(false);
break;
}
return super.dispatchTouchEvent(ev);
}
}

@ -9,7 +9,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
<io.legado.app.ui.widget.RecyclerViewAtViewPager2
android:id="@+id/rv_bookshelf"
android:layout_width="match_parent"
android:layout_height="match_parent"

@ -15,7 +15,7 @@
app:layout_constraintTop_toTopOf="parent"
app:title="@string/discovery" />
<androidx.recyclerview.widget.RecyclerView
<io.legado.app.ui.widget.RecyclerViewAtViewPager2
android:id="@+id/rv_find"
android:layout_width="match_parent"
android:layout_height="0dp"

@ -15,7 +15,7 @@
app:layout_constraintTop_toTopOf="parent"
app:title="@string/rss" />
<androidx.recyclerview.widget.RecyclerView
<io.legado.app.ui.widget.RecyclerViewAtViewPager2
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="0dp"

@ -4,7 +4,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
<io.legado.app.ui.widget.RecyclerViewAtViewPager2
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />

Loading…
Cancel
Save