【问题标题】:How disable user touch or scroll on recyclerview (autoscroll) Android?如何在 recyclerview (autoscroll) Android 上禁用用户触摸或滚动?
【发布时间】:2017-06-01 17:11:35
【问题描述】:

我在 RecyclerView 上实现了自动滚动,以使用 smoothScrollToPosition 像运行文本一样显示。它正在工作。

public void autoScroll() {
    final int speedScroll = 1000;
    runnableRunningAds = new Runnable() {
        @Override
        public void run() {
            rcRunningTextAds.smoothScrollToPosition(runningTextAdsAdapter.getItemCount());
            blnRunningAdsIsRunning = true;
            handlerRunningAds.postDelayed(this, speedScroll);
        }
    };
    handlerRunningAds.postDelayed(runnableRunningAds, speedScroll);
}

问题是当用户触摸 RecyclerView 时它会停止滚动。我已经尝试过this,,但它仍然无法正常工作。 RecyclerView 仍然停止滚动。

你知道吗? 谢谢。

【问题讨论】:

    标签: android android-recyclerview touch autoscroll


    【解决方案1】:

    尝试使用延迟后在单独的线程中工作

    private void disableTouch(){
    
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                recyclerView.addOnItemTouchListener(new 
                 RecyclerView.SimpleOnItemTouchListener() {
                @Override
                      public boolean onInterceptTouchEvent(RecyclerView rv, 
                       MotionEvent e) {
                      // true: consume touch event
                     // false: dispatch touch event
            return true;
       }
    });
            }
        }, 500);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-01
      • 2018-11-02
      • 2018-12-23
      • 1970-01-01
      相关资源
      最近更新 更多