有关RecyclerView的一些主题,在RecyclerView内部但我看到大部分都不适合我的情况。我的情况是我有一个RecyclerView(垂直线性布局管理)显示一个CardView列表,每个Cardview包含一个内部RecyclerView(水平线性布局管理)。问题是滚动时的性能问题,根本不流畅。我注意到如果我注释掉内部RecyclerView的setAdapter,滚动会变得更加平滑,但我使CardView没有更新新的列表。代码类似于这样:
onBindViewHolder...{
holder.innerRecycler.setAdapter(new InnerAdapter((data));
// comment that line make the outer recyclerview smoothly but the CardView data not updated thanks to the view recycling.
}
我知道在一个可滚动的视图中放置另一个可滚动的视图并不是一个好主意,但我看不到其他选择。有人遇到过这种布局吗?谢谢。
更新(添加更多代码)。
// init outer recyclerview
mOuterRecyclerView = (RecyclerView) findViewById(...);
mOuterRecyclerView.setLayoutManagement(new LinearLayoutManagement(this));
mOuterRecyclerView.setHasFixedSize(true);
mOuterRecyclerView.setAdapter(new OuterAdapter(dataList));
// The adapter class for the outer one
onBindViewHolder(...){
final dataItem = mItems.get(position);
holder.innerRecycler.setAdapter(new InnerAdapter(dataItem.getList()));
}
// the holder for the outer
class MyHolder extends ViewHolder{
RecyclerView innerRecycler;
public MyHolder(View view){
super(..);
innerRecycler = findViewById(...);
}
}
// the adapter for the inner
onBindViewHolder(...){
final dataItem = mItems.get(pos);
// async loading
holder.tvTitle.setText(dataItem.getTitle);
}
布局很简单,所以我不在这里发布完整代码。 :)
RecyclerView
的内容移动到其他地方,可能是点击弹出窗口或新窗口中。 至于您的问题,如果没有看到您具体执行的操作,我们无法进行调试。 - Droidman