0

私はほとんどこれを持っています:https://github.com/RyanHurst/TvProgramRecyclerView。水平リサイクル業者は、垂直リサイクル業者の項目として扱われます。すべての水平リサイクルビューのスクロールが同期化されます(表示アイテムのみ)。縦型リサイクルビュー内の横型リサイクルビュー

Horizo​​talスクロールは非常にスムーズですが、垂直スクロールは実際には悪いです。水平スクロールの位置0にスクロールすると、非常にうまく動作しますが、ほとんどの場合、スクロールが最も遅く右にスクロールします。私はonBinViewHolderでリサイクラーアダプターを設定せず、すべての水平リサイクラーに共通のrecyclerviewpoolを使用して何もしませんでした。

答えて

0

この拡張クラス使用、外側の垂直RecyclerViewの親RecyclerView

+0

私は前にそれを試してみた –

2

に(偽)setNestedScrollingEnabled設定してみてください:この拡張クラスを使用し、内側の水平RecyclerViewについて

public class BetterRecyclerView extends RecyclerView{ 
    private static final int INVALID_POINTER = -1; 
    private int mScrollPointerId = INVALID_POINTER; 
    private int mInitialTouchX, mInitialTouchY; 
    private int mTouchSlop; 
    public BetterRecyclerView(Context context) { 
    this(context, null); 
    } 

    public BetterRecyclerView(Context context, @Nullable AttributeSet attrs) { 
    this(context, attrs, 0); 
    } 

    public BetterRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) { 
    super(context, attrs, defStyle); 
    final ViewConfiguration vc = ViewConfiguration.get(getContext()); 
    mTouchSlop = vc.getScaledTouchSlop(); 
    } 

    @Override 
    public void setScrollingTouchSlop(int slopConstant) { 
    super.setScrollingTouchSlop(slopConstant); 
    final ViewConfiguration vc = ViewConfiguration.get(getContext()); 
    switch (slopConstant) { 
     case TOUCH_SLOP_DEFAULT: 
     mTouchSlop = vc.getScaledTouchSlop(); 
     break; 
     case TOUCH_SLOP_PAGING: 
     mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(vc); 
     break; 
     default: 
     break; 
    } 
    } 

    @Override 
    public boolean onInterceptTouchEvent(MotionEvent e) { 
    final int action = MotionEventCompat.getActionMasked(e); 
    final int actionIndex = MotionEventCompat.getActionIndex(e); 

    switch (action) { 
     case MotionEvent.ACTION_DOWN: 
     mScrollPointerId = MotionEventCompat.getPointerId(e, 0); 
     mInitialTouchX = (int) (e.getX() + 0.5f); 
     mInitialTouchY = (int) (e.getY() + 0.5f); 
     return super.onInterceptTouchEvent(e); 

     case MotionEventCompat.ACTION_POINTER_DOWN: 
     mScrollPointerId = MotionEventCompat.getPointerId(e, actionIndex); 
     mInitialTouchX = (int) (MotionEventCompat.getX(e, actionIndex) + 0.5f); 
     mInitialTouchY = (int) (MotionEventCompat.getY(e, actionIndex) + 0.5f); 
     return super.onInterceptTouchEvent(e); 

     case MotionEvent.ACTION_MOVE: { 
     final int index = MotionEventCompat.findPointerIndex(e, mScrollPointerId); 
     if (index < 0) { 
      return false; 
     } 

     final int x = (int) (MotionEventCompat.getX(e, index) + 0.5f); 
     final int y = (int) (MotionEventCompat.getY(e, index) + 0.5f); 
     if (getScrollState() != SCROLL_STATE_DRAGGING) { 
      final int dx = x - mInitialTouchX; 
      final int dy = y - mInitialTouchY; 
      final boolean canScrollHorizontally = getLayoutManager().canScrollHorizontally(); 
      final boolean canScrollVertically = getLayoutManager().canScrollVertically(); 
      boolean startScroll = false; 
      if (canScrollHorizontally && Math.abs(dx) > mTouchSlop && (Math.abs(dx) >= Math.abs(dy) || canScrollVertically)) { 
      startScroll = true; 
      } 
      if (canScrollVertically && Math.abs(dy) > mTouchSlop && (Math.abs(dy) >= Math.abs(dx) || canScrollHorizontally)) { 
      startScroll = true; 
      } 
      return startScroll && super.onInterceptTouchEvent(e); 
     } 
     return super.onInterceptTouchEvent(e); 
     } 

     default: 
     return super.onInterceptTouchEvent(e); 
    } 
    } 
} 

を:

public class FeedRootRecyclerView extends BetterRecyclerView{ 
    public FeedRootRecyclerView(Context context) { 
    this(context, null); 
    } 

    public FeedRootRecyclerView(Context context, @Nullable AttributeSet attrs) { 
    this(context, attrs, 0); 
    } 

    public FeedRootRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) { 
    super(context, attrs, defStyle); 
    } 

    @Override 
    public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) { 
`` /* do nothing */ 
    } 
} 

ここでは、これらのクラスが行うことについての適切な説明があります。http://nerds.headout.com/fix-horizontal-scrolling-in-your-android-app/

+0

素晴らしいリファレンス、あなたの答えは間違っています - どちらも外側のRecycler View用です。 – Mick

+0

@Mick記事から借りて、私のユースケースにいくつかの変更を加えました。 IIRCでは、内部のrecyclerviewのスクロールに小さな問題がありました。私は私のアプリで上記の2つのクラスを使用しており、それは完全に正常に動作します。 – milindbableshwar

関連する問題