禁止滑动:禁止竖向滑动 和 禁止横向滑动
- 线性布局 :禁止滑动 :Java
//禁止滑动 布局管理器
LinearLayoutManager linearLayoutManager=new LinearLayoutManager(this){
//禁止竖向滑动 RecyclerView 为垂直状态(VERTICAL)
@Override
public boolean canScrollVertically() {
return false;
}
//禁止横向滑动 RecyclerView 为水平状态(HORIZONTAL)
/*@Override
public boolean canScrollHorizontally() {
return false;
}*/
};
recyclerView.setLayoutManager(linearLayoutManager);
- 线性布局 :禁止滑动 :Kotlin
val linearLayoutManager: LinearLayoutManager = object : LinearLayoutManager(this) {
//禁止竖向滑动 RecyclerView 为垂直状态(VERTICAL)
override fun canScrollVertically(): Boolean {
return false
}
/**
override fun canScrollHorizontally(): Boolean {
return false
}
*/
recyclerView.setLayoutManager(linearLayoutManager);
- 网格布局 :禁止滑动 :Java
StaggeredGridLayoutManager manager=new StaggeredGridLayoutManager(3,StaggeredGridLayoutManager.VERTICAL){
//禁止竖向滑动 RecyclerView 为垂直状态(VERTICAL)
@Override
public boolean canScrollVertically() {
return false;
}
};
/**
//禁止横向滑动 RecyclerView 为水平状态(HORIZONTAL)
@Override
public boolean canScrollHorizontally() {
return false;
}
};
*/
recyclerView.setLayoutManager(manager);
- 网格布局 :禁止滑动 :Kotlin
staggermanager= object : StaggeredGridLayoutManager(5, VERTICAL) {
override fun canScrollVertically(): Boolean {
return false
}
/**
override fun canScrollHorizontally(): Boolean {
return false
}
*/
}
recyclerView.layoutManager=staggermanager