parent
6e69efb34e
commit
ba37b48969
@ -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); |
||||
} |
||||
} |
Loading…
Reference in new issue