滚动第二个时滚动RecyclerView

时间:2017-04-24 14:45:09

标签: android android-recyclerview

我在我的主要活动中有RecyclerView个:一个是水平的,另一个是垂直的。我的问题是,当我向下滚动第二个回收器时,我希望上部回收器也能滚动,但事实并非如此。它保持不变。

这是我的代码:

recyclerView = (RecyclerView) findViewById(R.id.recyclerview1);
recylerViewLayoutManager = new LinearLayoutManager(context,LinearLayoutManager.HORIZONTAL,false);
recyclerView.setLayoutManager(recylerViewLayoutManager);
recyclerViewAdapter = new RecyclerViewAdapter(MainActivity.this, subjects,images);
recyclerView.setAdapter(recyclerViewAdapter);


MainGridRecView = (RecyclerView) findViewById(R.id.maingridrc);
MainGridRecViewLayoutManager = new GridLayoutManager(context,2);
MainGridRecView.setLayoutManager(MainGridRecViewLayoutManager);
MainGridRecViewAdapter = new MainGridRecyclerViewAdapter(MainActivity.this, subjects,images);
MainGridRecView.setAdapter(MainGridRecViewAdapter);

1 个答案:

答案 0 :(得分:0)

您可以添加RecyclerView.OnScrollListener并手动滚动另一个RecyclerView

recyclerView1.addOnScrollListener(new RecyclerView.OnScrollListener() {
    @Override
    public void onScrolled(final RecyclerView recyclerView, final int dx, final int dy) {
        recyclerView2.setScrollX(dx);
        recyclerView2.setScrollY(dy);
    }
});

虽然我没有达到你想要达到的效果,但至少你会得到这个概念。