Recyclerview in Android implements multi-level folding list effect (treerecyclerview)

preface

First, we have to make complaints about the products. Why do Nima want to do this?... it's not good to have a two level. Level 3, level 4, it's said that there are level 6... Such crazy design is not easy to give data in the background.

Let's see the effect first:

Two level effect:

Three level effect:

Effect of full expansion (I only wrote level 5)

Tell me why you wrote this:

After the company's products put forward the three-level demand, I looked online

The first one to find is that the implementation is actually expandlistview nesting

Looking for the second is too laggy, ExpandRecyclview, and then use the chant, found that the three level development is very card, see the source code.

Recyclerview set found

Is there anything that is not nested

Then find Hongyang's blog and write it

Talk about ideas:

1. Treeadapter should only care about the contents of list < treeadapteritem > data

2. Treat each item as an independent individual. The layout style, the proportion of each row, and the bindviewholder are determined by their own.

3. Each item should only care about its own data and its own data at the next level, not its superiors and subordinates

4. For the implementation of expansion, item takes out the sub data set and adds it to list < treeadapteritem > data to become its own level, because each expansion will expand only one level of data.

5. Collapse, recursively traverse all sub data, recursively get all sub data sets (understandably, because all files in a folder, including all files in a sub folder), and then delete these data from list < treeadapteritem > data.

See code:

Let's look at the adapter

Specific use:

If you want to set different layouts at the same level, then look

Update and explanation:

For more in-depth introduction, you can view this article: http://www.jb51.net/article/113516.htm

The demo download address is attached below:

GitHub portal: treerecyclerview

Local download: http://xiazai.jb51.net/201705/yuanma/TreeRecyclerView (jb51.net).rar

summary

The above is the whole content of this article. I hope the content of this article can bring some help to your study or work. If you have any questions, you can leave a message. Thank you for your support for programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>