RecycleView不可滑动,固定高度,设置setNestedScrollingEnabled(false)后滑动时上下有滑动越界效果,需要重写LayoutManger使LayoutManager不可滑动
LinearLayoutManger:
/**
* 不可滑动
*/
public class CustomLinearLayoutManager extends LinearLayoutManager {
private boolean isScrollEnabled = true;
public CustomLinearLayoutManager(Context context) {
super(context);
}
public void setScrollEnabled(boolean flag) {
this.isScrollEnabled = flag;
}
/**
* 禁止滑动
* canScrollHorizontally(禁止横向滑动)
*
* @return
*/
@Override
public boolean canScrollHorizontally() {
return isScrollEnabled && super.canScrollVertically();
}
/**
* 禁止滑动
* canScrollVertically(禁止竖向滑动)
*
* @return
*/
@Override
public boolean canScrollVertically() {
return isScrollEnabled && super.canScrollVertically();
}
}
GridLayoutManager:
/**
* 不可滑动
*/
public class CustomGridLayoutManager extends GridLayoutManager {
private boolean isScrollEnabled = true;
public CustomGridLayoutManager(Context context, int spanCount) {
super(context, spanCount);
}
public void setScrollEnabled(boolean flag) {
this.isScrollEnabled = flag;
}
/**
* 禁止滑动
* canScrollHorizontally(禁止横向滑动)
*
* @return
*/
@Override
public boolean canScrollHorizontally() {
return isScrollEnabled && super.canScrollVertically();
}
/**
* 禁止滑动
* canScrollVertically(禁止竖向滑动)
*
* @return
*/
@Override
public boolean canScrollVertically() {
return isScrollEnabled && super.canScrollVertically();
}
}
网友评论