我在动态创建具有不同布局的recyclerView时遇到问题。我想使一些对象处于水平方向,而保持垂直。两者都是recyclerView。 下面的代码,我有什么:
parentLayout = new RelativeLayout(getContext());
RelativeLayout.LayoutParams layoutParams = new
RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.MATCH_PARENT);
for (Map.Entry<Integer, ArrayList<Object>> entry : items.entrySet()) {
adapter = new CustomAdapter(getContext(), entry.getValue())
View view = inflater.inflate(R.layout.recycler, container, false);
if (view instanceof RecyclerView) {
recyclerView = (RecyclerView) view;
CustomLayout cl = new CustomLayout();
LinearLayoutManager lm = new LinearLayoutManager(getContext());
recyclerView.setAdapter(adapter);
recyclerView.setItemAnimator(null);
recyclerView.setLayoutManager(ifSomething ? cl : lm);
}
parentLayout.addView(view, layoutParams);
}
此刻,我收到多个recycleView重叠,我只想将它们加在一起。
答案 0 :(得分:1)
嗯,我不认为您想实现多个recyclerviews。您只需要实现一个recyclerview并创建2个视图持有者,其中一个具有水平linearlayout,一个具有垂直linearlayout。将适配器添加到您的recyclerview中,该适配器管理列表中的项目,并将其转换为适合您的recyclerview的视口。 Recyclerviews仅用于显示包含多个项目的列表。并不是真正要显示为多个视图。
请按照此链接中的步骤操作:https://developer.android.com/guide/topics/ui/layout/recyclerview