Click not working on RecyclerView in CoordinatorLayout when scrolling

♀尐吖头ヾ 提交于 2019-11-30 03:46:25

Google just posted a workaround for this bug, it will be publicly released later.

https://gist.github.com/chrisbanes/8391b5adb9ee42180893300850ed02f2

If Using RecyclerView in NestedScrollView add this line to RecyclerView :

android:nestedScrollingEnabled="false"

I hope it help you.

I also found this problem ... after wasting so many hours searching and trying different things, I came out with a trick, its not pretty but it could work for someone else too.

Basically the idea is simulate a click on the nestedScrollView.

In my case after I detect the 'AppBarLayout' its fully expanded, I send a tap to the nested.

protected void onCreate(final Bundle savedInstanceState) {

    getAppBarLayout().addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {

      @Override
      public void onOffsetChanged(final AppBarLayout appBarLayout, final int verticalOffset) {

          if (verticalOffset == 0) { 
              // State.EXPANDED
              simulatedClick(nestedScroll)
          } else if (Math.abs(verticalOffset) >= appBarLayout.getTotalScrollRange()) { 
              // State.COLLAPSED
          } else { 
              // State.IDLE
          }
      }
  });
}

private void simulatedClick(@NonNull final View view) {
    // Obtain MotionEvent object
    final long downTime = SystemClock.uptimeMillis();
    final long eventTime = SystemClock.uptimeMillis() + 100;
    final MotionEvent motionEvent = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_UP, 0.0f, 0.0f, 0);
    // Dispatch touch event to view
    view.dispatchTouchEvent(motionEvent);
}

NOTE: I don't really recommend the use of hacks like this, it's unprofessional and unmaintainable, but the more you know...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!