2017-12-05 4 views
2

두 개의 중첩 된 RecyclerView이 있습니다. 그 중 하나는 수직 스 와이프를 관리하고 그 중 하나는 수평 스 와이프를 처리합니다. 내가 직면하고있는 문제는 수평 RecyclerView의 스크롤이 때로는 예상대로 작동하지 않는다는 것입니다. 때로는 수평 스 와이프를 인식하지 못하고 수직 스 와이프 만 수행합니다. 수평 스 와이프하려면 수평 방향으로 실제로 직선을 그리는 것이 필요합니다. 수직 스 와이프로 인식 될 수 있습니다. UX를 개선하기 위해 조정할 수있는 매개 변수가 있습니까?두 개의 중첩 된 RecyclerViews의 스크롤 동작

외부 레이아웃 :

<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

사실 그것은 조금 복잡합니다. 분명히 할 수 있는지 확실하지 않습니다. 하지만 기본적으로 우리는 json 유형에 따라 다른 모듈을 인스턴스화하는 외부 모듈 용 대리자로 대리인을 갖습니다. 각 세로 모듈은 사용자 정의보기 및 가능하면 다른 RecyclerView가있는 다른 ViewHolder를 만듭니다. – 4ndro1d

답변

0

당신은 자기 정의 RecyclerView을 만든 다음 outter는의 RecyclerView의 onInterceptTouchEvent 절편 터치 이벤트를 재정의해야

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; 
}