0

When a user touches a ViewHolder (it has horizontal scroll enabled), depending on the angle of the scroll, I need to decide if it's parent Recyclerview needs to be triggered or the viewHolder's scroll needs to process that touch itself. Here is a rough layout of my activity. layout design The recycler view Horizontal is one of the various View Holders of it's parent recyclerview

Harsha Vardhan
  • 446
  • 4
  • 15

1 Answers1

0

You Can set Scroll listener to the recycle view and check the direction of recycle view

 mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                switch (newState) {
                    case RecyclerView.SCROLL_STATE_IDLE:
                        System.out.println("The RecyclerView is not scrolling");
                        break;
                    case RecyclerView.SCROLL_STATE_DRAGGING:
                        System.out.println("Scrolling now");
                        break;
                    case RecyclerView.SCROLL_STATE_SETTLING:
                        System.out.println("Scroll Settling");
                        break;

                }

            }

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                if (dx > 0) {
                    System.out.println("Scrolled Right");
                } else if (dx < 0) {
                    System.out.println("Scrolled Left");
                } else {
                    System.out.println("No Horizontal Scrolled");
                }

                if (dy > 0) {
                    System.out.println("Scrolled Downwards");
                } else if (dy < 0) {
                    System.out.println("Scrolled Upwards");
                } else {
                    System.out.println("No Vertical Scrolled");
                }
            }
        });
Dulanga
  • 921
  • 11
  • 23
  • How do you assign that scroll to it's viewHolder then? – Harsha Vardhan May 24 '19 at 07:29
  • do you need to scroll vertically recycle(vertical ) view with map view and when you scroll horizontally child horizontal recycle view need scroll or something else – Dulanga May 24 '19 at 07:36
  • It just needs to work like the Play Store app, where each swipe scrolls either the horizontal one or the vertical. The Play Store is the best example. – Harsha Vardhan May 24 '19 at 07:37
  • then you can check this stack overflow questions https://stackoverflow.com/questions/34549414/nested-recyclerview-like-google-play-store-app and these example codes http://khmertechtrain.tk/index.php/2017/10/03/create-a-vertical-scroll-and-horizontal-scroll-app-like-google-play-store/ and this https://github.com/Ranjan101/RecyclerView-Google-Play – Dulanga May 24 '19 at 07:42