2017-12-05 12 views
2

2つのネストされたRecyclerViewがあります。そのうちの1つは垂直スワイプを管理し、その1つは水平スワイプを処理します。私が直面している問題は、水平RecyclerViewのスクロールが時々期待どおりに動作しないことです。ときには水平スワイプを認識せず、垂直スワイプだけを行うことがあります。水平スワイプを作成するには、実際に水平方向に直線を描く必要があります。数度オフにすると垂直スワイプとして認識されます。UXを改善するために、調整可能なパラメータはありますか?2つのネストされたRecyclerViewのスクロール動作

外レイアウト:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@android:color/white" 
android:gravity="center"> 

<ProgressBar 
    android:id="@+id/pb_new_home" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true" /> 

<android.support.v7.widget.RecyclerView 
    android:id="@+id/rv_modules" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:clipToPadding="false" 
    android:nestedScrollingEnabled="false" 
    android:paddingBottom="@dimen/newhome_recyclerview_paddingbottom" /> 
</RelativeLayout> 

インナーレイアウト:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
style="@style/NewHomeModuleContainer"> 

<TextView 
    android:id="@+id/tv_module_title" 
    style="@style/NewHomeModuleTitle" /> 

<android.support.v7.widget.RecyclerView 
    android:id="@+id/rv_horizontal_recycler" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_above="@+id/tv_show_more" 
    android:layout_below="@id/tv_module_title" 
    android:layout_marginBottom="-8dp" 
    android:clipToPadding="false" 
    android:paddingEnd="28dp" 
    android:paddingRight="28dp" /> 

</RelativeLayout> 
+0

onInterceptTouchEventインターセプトタッチイベントをオーバーライドする必要があります実際にはちょっと複雑ですが、私がそれを明確にすることができるかどうかは分かりません。しかし、基本的には外部モジュール用のDelegate as Adapterがあり、jsonタイプに応じて異なるモジュールをインスタンス化します。各垂直モジュールは、カスタムViewと別のRecyclerViewを持つ別のViewHolderを作成します – 4ndro1d

答えて

0

あなたは自己定義RecyclerViewを作成し、outterのRecyclerView

boolean moveInnerRv; 
private float startY; 

@Override 
public boolean onInterceptTouchEvent(MotionEvent ev) { 
    float currentY = -1; 
    switch(ev.getAction()){ 
     case MotionEvent.ACTION_DOWN: 
      startY = ev.getRawY(); 
      break; 

     case MotionEvent.ACTION_MOVE: 
      currentY = ev.getRawY(); 
      break; 

     case MotionEvent.ACTION_CANCEL: 
     case MotionEvent.ACTION_UP: 

      break; 

     default: 
      break; 
    } 
    // if move distance over 100, pass touch to inner RecyclerView 
    moveInnerRv = !((currentY - startY) > 100); 

    return moveInnerRv; 
} 
関連する問題