简体   繁体   中英

Android RecyclerView item dynamic layout

Inside my recycler view item layout I want to add something like horizontal recyclerview layout, because I don't know how many ImageViews I need, that's why I can't create them as a static layout. The number of icons depends on server logic. How can achieve something like the picutre below? Thank you in advance!

在此处输入图像描述

You Need Add Horizontal Recyclerview Inside The Main Recyclerview. Your First RecyclerView is Verticle list and inside every index create another RecyclerView It's a Horizontal. so you can display n number of Imageview.

You have to create Recyclerview inside the child layout of your main Recyclerview

Something like

Suppose this is the Main Recyclerview

     <androidx.recyclerview.widget.RecyclerView
                        android:id="@+id/mainRecyclerview"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="vertical"
                        tools:listitem="@layout/item_demo" />

In your child layout, Let's say item_demo you have to add another Recyclerview for the imageView that you want to show in horizontal

<androidx.recyclerview.widget.RecyclerView
                        android:id="@+id/mainRecyclerview"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal"
                        tools:listitem="@layout/item_child" />

item_child layout contains the Imageview that will display horizontally

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