Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 具有不同布局的多个回收器视图_Java_Android_Layout_Android Recyclerview_Android Relativelayout - Fatal编程技术网

Java 具有不同布局的多个回收器视图

Java 具有不同布局的多个回收器视图,java,android,layout,android-recyclerview,android-relativelayout,Java,Android,Layout,Android Recyclerview,Android Relativelayout,我在动态创建具有不同布局的recyclerView时遇到问题。我想让一些对象保持水平方向,保持垂直方向。两者都是回收视图。 以下代码,我所拥有的: parentLayout = new RelativeLayout(getContext()); RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, Relativ

我在动态创建具有不同布局的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);
}
parentLayout=newrelativelayout(getContext());
RelativeLayout.LayoutParams LayoutParams=新建
RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_父级,
RelativeLayout.LayoutParams.MATCH_PARENT);
for(Map.Entry:items.entrySet()){
适配器=新的CustomAdapter(getContext(),entry.getValue())
视图=充气机。充气(R.layout.recycler,container,false);
如果(查看RecyclerView的实例){
recyclerView=(recyclerView)视图;
CustomLayout cl=新的CustomLayout();
LinearLayoutManager lm=新的LinearLayoutManager(getContext());
recyclerView.setAdapter(适配器);
recyclerView.setItemAnimator(空);
recyclerView.setLayoutManager(ifSomething?cl:lm);
}
parentLayout.addView(视图,布局参数);
}

此时,我收到多个recycleView重叠,我只想将它们加在另一个下面。

嗯,我认为你不想实现多个recycleView。您只需要实现一个recyclerview并创建两个视图保持架—一个具有水平线性布局,另一个具有垂直线性布局。向您的recyclerview添加一个适配器,用于管理列表中的项目,并将它们转换为recyclerview的右视图持有者。Recyclerviews仅用于显示包含多个项目的列表。这并不意味着要显示为多个视图


请按照此链接中的步骤进行操作:

如果您只想在上一个页面的下方添加一个页面,请使用垂直线性布局而不是相对布局。我需要创建具有换行内容高度的recyclerView,并且它仅适用于相对布局