【发布时间】:2019-10-19 19:50:40
【问题描述】:
我在动态创建具有不同布局的 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重叠,我只想将它们添加到另一个之下。
【问题讨论】:
-
如果你只想要一个低于前一个,使用垂直线性布局而不是相对布局
-
我需要创建带有 wrap_content 高度的 recyclerView,它只适用于相对布局
标签: java android layout android-recyclerview android-relativelayout