I found a very simple solution which stops all vertical scrolling in the recycle view. This took me about half day to figure out but now is really simple and elegant I think.
create a java class that extends recycler view with all the constructors found in the recycler view. in your xml make sure that you change it to the new widget. Then you have to Overide to methods: onInterceptTouchEvent
and computeVerticleScrollRange
. There is a bug in the recycler view that it will still interrupt scroll events.
so:
public class FooRecyclerView extends RecyclerView {
private boolean verticleScrollingEnabled = true;
public void enableVersticleScroll (boolean enabled) {
verticleScrollingEnabled = enabled;
}
public boolean isVerticleScrollingEnabled() {
return verticleScrollingEnabled;
}
@Override
public int computeVerticalScrollRange() {
if (isVerticleScrollingEnabled())
return super.computeVerticalScrollRange();
return 0;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent e) {
if(isVerticleScrollingEnabled())
return super.onInterceptTouchEvent(e);
return false;
}
public FooRecyclerView(Context context) {
super(context);
}
public FooRecyclerView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public FooRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
}
from
RecyclerView
android:id="@+id/task_sub_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
to
com.customGoogleViews.FooRecyclerView
android:id="@+id/task_sub_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
Now in your code you just have to control the state of your recycler view with the disableVerticleScroll
method and your all set.