Reputation: 15535
I need to fix scrolling in recyclerview, If user deletes one of the visible view only I want to show invisible view on the available position. I have tried following things,
added
android:overScrollMode="never"
on xml, and
recyclerView.setHasFixedSize(false);
on Java, But nothing helps, any help will be highly appreciable.
Thanks.
Update
I want to disable scrolling option, user can only see the invisible item after deleting one of the visible item.
Upvotes: 3
Views: 8824
Reputation: 51
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.
Upvotes: 5