简体   繁体   中英

Multiple recycler views with different layouts

I have a problem with dynamic creation of recyclerView with different layouts. I want to have some objects in horizontal orientation and remaining in vertical. Both are recyclerView. Below code, what I have:

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);
}

At this moment, I receive multiple recycleView overlapping, and I just want to add up them under the other.

Uhm I don't think u want to implement multiple recyclerviews. You only need to implement one recyclerview and create 2 viewholders one with a horizontal linearlayout and one with a vertical linearlayout. Add an adapter to your recyclerview which manages the items of your list and convert them to the right viewholder for your recyclerview. Recyclerviews are only used for showing a list with multiple items. There not really meant to be shown as multiple views.

Please follow the steps in this link: https://developer.android.com/guide/topics/ui/layout/recyclerview

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM