我无法在 RecyclerView
中禁用滚动。我尝试调用 rv.setEnabled(false)
但我仍然可以滚动。
如何禁用滚动?
原文由 Zsolt Safrany 发布,翻译遵循 CC BY-SA 4.0 许可协议
我无法在 RecyclerView
中禁用滚动。我尝试调用 rv.setEnabled(false)
但我仍然可以滚动。
如何禁用滚动?
原文由 Zsolt Safrany 发布,翻译遵循 CC BY-SA 4.0 许可协议
您可以创建一个扩展 Recycler View 类的 Non Scrollable Recycler View,如下所示:
import android.content.Context;
import android.util.AttributeSet;
import android.view.ViewGroup;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;
public class NonScrollRecyclerView extends RecyclerView {
public NonScrollRecyclerView(Context context) {
super(context);
}
public NonScrollRecyclerView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public NonScrollRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onMeasure(int widthMeasure, int heightMeasure) {
int heightMeasureCustom = MeasureSpec.makeMeasureSpec(
Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasure, heightMeasureCustom);
ViewGroup.LayoutParams params = getLayoutParams();
params.height = getMeasuredHeight();
}
}
原文由 Aman Garg 发布,翻译遵循 CC BY-SA 4.0 许可协议
2 回答1.3k 阅读✓ 已解决
2 回答2.6k 阅读
2 回答1.7k 阅读
1 回答2.1k 阅读
1 回答1.1k 阅读
1 回答1.3k 阅读
1.3k 阅读
为此,您应该覆盖
layoutManager
的recycleView
。这样它只会禁用滚动,没有其他功能。您仍然可以处理点击或任何其他触摸事件。例如:-原来的:
在这里使用“isScrollEnabled”标志,您可以临时启用/禁用回收视图的滚动功能。
还:
简单地覆盖您现有的实现以禁用滚动并允许单击。
在科特林: