滚动多个水平RecyclerView在一起 [英] Scroll multiple horizontal RecyclerView together

查看:615
本文介绍了滚动多个水平RecyclerView在一起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个EPG一样的显示效果,对此我有多个水平 RecyclerView S(如电视节目)一个LinearLayout中的内部封装。当我滚动RecyclerView之一,我想要的意见,其余将被滚动起来。

I'm creating an EPG like view for which I have multiple horizontal RecyclerViews (as tv programs) encapsulated inside a LinearLayout. When I scroll one of the RecyclerView, I want the rest of the views to be scrolled 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);
    }
}

我尝试添加滚动监听我的意见,但我很困惑与 RecyclerView.OnScrollListener onScrolled 方式,我可以'吨弄清楚如何滚动其他意见。

I've tried adding a scroll listener to my views but I'm confused with RecyclerView.OnScrollListener's onScrolled method as i can't figure out how to scroll other views.

任何帮助/建议,将是有益的。

Any help/suggestion would be helpful.

电视频道视图

推荐答案

您需要随时重新计算水平回收的观点经常项目的(下一HRV)的位置 滚动在一个h.r.v.后基于少量的卷动的重新计算别人的立场发生在触及HRV

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.

然后重写 onViewAttachedToWindow 适配器和使用方法 scrollToPositionWithOffset LinearLayoutManager 将其设置为正确的位置。

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

另外计算运动DX的时候,不要忘了关闭 onScrolled 方法的手指,以避免重复处理同样的事件。

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

这篇关于滚动多个水平RecyclerView在一起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆