Scroll multiple horizontal RecyclerView together

十年热恋 提交于 2019-11-30 04:12:10

HorizontelScrollView

{

Linear Layout

{

Vertical list of horizontal recycler views , override horizontal recycler view's LayoutManager's
canScroolhorizontally() method to return false ,so that they all scroll together according to the Grand Parent ScrollView.

}

Our main focus is to scroll that vertical list of horizontal recycler views horizontally , first i tried to keep all of them on a horizontal scroll view ,but that is something ,which the android system clearly rejects , so i kept one linear layout (in my case vertically oriented ) as a mediator.

so the epg grid now can scroll in vertically as they are inside one vertical recycler view as well as in horizontally because of the Horizontal scroll view. and we should not allow horizontal list to scroll independentaly ,so I extended layoutmanager and disallow horizontal scrolling ,now they only scroll under grandParent scroll .

You need to always re-calculate position of current items in horizontal recycler views(next h.r.v.) After scrolling in one h.r.v. re-calculate positions of others based on small amount of scroll movement occured in touched h.r.v.

Then override onViewAttachedToWindow in adapter and use method scrollToPositionWithOffset from LinearLayoutManager of particularly h.r.v to set it to right position.

Also when calculating movement dx, don't forget to disable onScrolled method when finger is down to avoid multiple handling of the same event.

FlexboxLayout (made by Google) lets you make something like this with a RecyclerView and a FlexboxLayoutManager. Since its version 3.0(June 28th 2017) you can drag horizontally through it.

For your example use it like this:

    FlexboxLayoutManager layoutManager = new FlexboxLayoutManager(getActivity());
    layoutManager.setFlexDirection(FlexDirection.ROW);
    layoutManager.setFlexWrap(FlexWrap.WRAP);
    recyclerView.setLayoutManager(layoutManager);

And don't forget to set the width of your RecyclerView to a bigger number than the screen size, in order to scroll, do not use match_parent:

<android.support.v7.widget.RecyclerView
        android:layout_width="3600dp"
        android:layout_height="match_parent"/>

Note: the ViewHolders are recycled by rows, not by columns, so be careful if you have too heavy items on a very long RecyclerView

You need to add textviews in horizontal rows. The length of the textview depends on the duration of the program. I have hosted a sample project on Github. Feel free to clone. https://github.com/xardox69/android_EPG

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