1

I want a screen with recycler view at bottom and another horizontal list at top.

But when i scroll the recycler view it should not go under the horizontal list but they should move as they are part of one screen.

Is it possible ? Will I be needing co-ordinator layout or nested scrolling ?

Gaurav
  • 667
  • 2
  • 13
  • 28

1 Answers1

0

All you need is nested RecyclerView, one parent one and another inside it and you need this CallBack to handle swipe events

private final ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {

    @Override
    public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
        return false;
    }

    @Override
    public void onSwiped(RecyclerView.ViewHolder viewHolder, int swipeDir) {

        //HERE YOU WILL PERFORM YOUR ACTION FOR SWIPE EVENT i.e CHANGE THE ITEM NO IN RECYCLERVIEW WITH SOMETHING LIKE 
        // mViewPager.setCurrentItem(mViewPager.getCurrentItem() + 1);
    }
};

private final ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback);

}

and then you will need to attach it to both RecyclerViewslike this

itemTouchHelper.attachToRecyclerView(mRecyclerView1);
itemTouchHelper.attachToRecyclerView(mRecyclerView2);

This is how you can handle swipe events for both RecyclerViews at same time

and this is how you can add and remove pages from ViewPager

public void MoveNext(View view) {
//it doesn't matter if you're already in the last item
pager.setCurrentItem(pager.getCurrentItem() + 1);
}

public void MovePrevious(View view) {
    //it doesn't matter if you're already in the first item
    pager.setCurrentItem(pager.getCurrentItem() - 1);
}

Hope this helps

Atiq
  • 14,435
  • 6
  • 54
  • 69