我的设置很简单:
内容onCreate()
:
layoutManager = new LinearLayoutManager( this ); layoutManager.setOrientation( LinearLayoutManager.HORIZONTAL ); topTopicRecyclerView.setLayoutManager( layoutManager );
现在,当我向左或向右滑动recyclelerView并且滑动角度不是完全水平时,SwipeRefreshLayout会跳入并接管滚动控件.这会导致recyclerView内部出现恼人的视觉"打嗝".
如果禁用SwipeRefreshLayout,一切都很好.
那么,如何在RecyclerView的区域上停用SwipeRefreshLayout的滚动控件?
根据关于SRL和HorizontalScrollView的讨论,我创建了对应的SwipeRefreshLayout
:
public class OnlyVerticalSwipeRefreshLayout extends SwipeRefreshLayout { private int touchSlop; private float prevX; private boolean declined; public OnlyVerticalSwipeRefreshLayout( Context context, AttributeSet attrs ) { super( context, attrs ); touchSlop = ViewConfiguration.get( context ).getScaledTouchSlop(); } @Override public boolean onInterceptTouchEvent( MotionEvent event ) { switch( event.getAction() ){ case MotionEvent.ACTION_DOWN: prevX = MotionEvent.obtain( event ).getX(); declined = false; // New action break; case MotionEvent.ACTION_MOVE: final float eventX = event.getX(); float xDiff = Math.abs( eventX - prevX ); if( declined || xDiff > touchSlop ){ declined = true; // Memorize return false; } break; } return super.onInterceptTouchEvent( event ); } }
和在XML中的用法: