Gun*_*lan 3 android android-recyclerview
我需要在recyclerview中修改滚动,如果用户只删除其中一个可见视图,我想在可用位置显示不可见的视图.我试过以下事情,
添加
android:overScrollMode="never"
Run Code Online (Sandbox Code Playgroud)
在xml上,和
recyclerView.setHasFixedSize(false);
Run Code Online (Sandbox Code Playgroud)
在Java上,但没有任何帮助,任何帮助将是非常值得注意的.
谢谢.
更新
我想禁用滚动选项,用户只能在删除其中一个可见项后才能看到隐藏项.
小智 5
我找到了一个非常简单的解决方案,它可以在循环视图中停止所有垂直滚动.这花了我大约半天的时间来弄清楚,但现在我觉得这很简单和优雅.
创建一个java类,它使用recycleler视图中的所有构造函数扩展Recycler视图.在您的xml中确保将其更改为新窗口小部件.然后你必须覆盖方法:onInterceptTouchEvent和computeVerticleScrollRange.回收站视图中存在一个错误,它仍然会中断滚动事件.
所以:
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);
}
}
Run Code Online (Sandbox Code Playgroud)
从
RecyclerView
android:id="@+id/task_sub_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
Run Code Online (Sandbox Code Playgroud)
至
com.customGoogleViews.FooRecyclerView
android:id="@+id/task_sub_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
Run Code Online (Sandbox Code Playgroud)
现在在您的代码中,您只需使用disableVerticleScroll方法和所有集合来控制回收器视图的状态.