Scroll a few horizontal RecyclerViews together

I am creating an EPG-like view for which I have several horizontal RecyclerView (in the form of television programs) encapsulated inside LinearLayout. When I view one of the RecyclerView, I want the rest of the views to scroll together.

 @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); layoutContent.setWeightSum(epg.getChannels().size()); //prepare recycler views and add into layoutContent based on epg channels for(EPG.Channel ch : epg.getChannels()){ AppLog.error(TAG, "Creating RecyclerView for: " + ch.getDisplayName()); //create new recycler view final RecyclerView rv = new RecyclerView(layoutContent.getContext()); lstRecyclerViews.add(rv); //set layout manager rv.setLayoutManager(new LinearLayoutManager(layoutContent.getContext(), LinearLayoutManager.HORIZONTAL, false)); //create adapter rv.setAdapter(new MyAdapter(ch.getPrograms())); rv.setItemAnimator(new DefaultItemAnimator()); //add into parent layout LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0); lp.weight = 1; layoutContent.addView(rv, lp); } } 

I tried to add a scroll listener to my views, but the RecyclerView.OnScrollListener onScrolled method confuses me, because I cannot figure out how to scroll through other views.

Any help / suggestion would be helpful.

Watching TV channels

+8
android scroll android-recyclerview epg
source share
3 answers

HorizontelScrollView

{

Line layout

{

Vertical list of horizontal views of recyclers; redefine horizontal view of recyclers of LayoutManager's canScroolhorizontally () to return false so that they all scroll together according to the Great Parent Scroll List.

}

Our main focus is on scrolling the vertical list of horizontal sections horizontally, at first I tried to save them all in the horizontal scroll view, but this is what the android system explicitly rejects, so I saved one linear layout (in my case, vertically oriented) as a pick.

therefore, the epg grid can now scroll vertically, since they are inside the same vertical view of the recycler, as well as horizontally due to horizontal scrolling. and we should not let the horizontal list scroll independently, so I expanded the layoutmanager and disabled horizontal scrolling, now they only scroll under grandParent scrolling.

+2
source share

You always need to recalculate the position of the current elements in the horizontal representations of the recyclers (next hrv) After scrolling in one hour. recalculate the positions of others based on a small amount of scroll movement that occurred in indirect hrv

Then override onViewAttachedToWindow in the adapter and use the scrollToPositionWithOffset method from LinearLayoutManager , especially hrv, to set it to the desired position.

Also, when calculating the movement of dx, do not forget to disable the onScrolled method when it does not work, to avoid multiple processing of the same event.

+1
source share

FlexboxLayout (made by Google) allows you to do something like this using RecyclerView and FlexboxLayoutManager . Starting with version 3.0 (June 28, 2017), you can drag it horizontally through it.

In your example, use it like this:

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

And remember to set the width of your RecyclerView to a larger number than the screen size, to scroll, do not use match_parent :

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

Note : ViewHolders processed row by row, not column by column, so be careful if your elements are too heavy on a very long RecyclerView

0
source share

All Articles