【问题标题】:RecyclerView disable scroll doesnot workRecyclerView 禁用滚动不起作用
【发布时间】:2018-07-25 18:55:03
【问题描述】:

我有一个水平滚动recyclerviewrecyclerviews 子项具有向上滑动面板。因此,当面板展开时,我想阻止 recyclerview 滚动。 在向上滑动面板展开之前,用户无法滚动到下一个项目。向上滑动面板折叠后,应启用 recyclerview 滚动。

这是recyclerview初始化代码

 mAdapter = new FootballFeedDetailAdapter(FootballFeedDetailActivity.this);
    linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
    recyclerView.setLayoutManager(linearLayoutManager);
    recyclerView.setAdapter(mAdapter);
    SnapHelper snapHelper = new PagerSnapHelper();
    snapHelper.attachToRecyclerView(footballFeedRecyclerView);

我尝试使用recyclerView.setNestedScrollingEnabled(false);

但它不起作用

从我的适配器中,如果上滑面板展开,我正在整理以下方法

public void setUpRecyclerViewScroll(boolean status) {
   footballFeedRecyclerView.setNestedScrollingEnabled(status);
}

提前致谢。如果有人回答这个问题,我会非常有帮助。

【问题讨论】:

    标签: android android-recyclerview horizontal-scrolling


    【解决方案1】:

    扩展 LinearLaoyutManager 并覆盖 canScrollHorizontally 方法。 当您的上滑面板展开/折叠时,调用 layoutmanager setScrollingEnabled(false/true)

    private static class HScrollManager extends LinearLayoutManager {
       private boolean scrollingEnabled = true;
    
       public void setScrollingEnabled(boolean enabled) {
           scrollingEnabled = enabled;
       }
    
       @Override
       public boolean canScrollHorizontally() {
           return scrollingEnabled && super.canScrollVertically();
       } 
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-25
      • 1970-01-01
      • 1970-01-01
      • 2020-11-10
      • 2015-08-12
      相关资源
      最近更新 更多