Example of the effect of Android folding recyclerview

Recyclerview has a high degree of freedom. It can be said that it can't be done only when you can't think of it. The more you use it, the more you like it. This time, a super simple method is used to make recyclerview with folding effect.

The effect is this.

To summarize the characteristics of this list, there are the following three points:

1. Overlapping effect;

2. Sense of hierarchy;

3. Differential effect of the first item.

Let's solve it one by one.

Let's create a new parallelaxrecyclerview, let it inherit recyclerview, and use linear layoutmanager as the layout manager.

Overlapping effect

In fact, each item has a part in front of it. We know that recyclerview can achieve the interval effect of the list by setting itemdecoration. Have you ever thought about what happens if the interval is set to a negative number? For example:

Yes, this achieves our overlapping effect.

Sense of level

In material design, there is the concept of z-axis. We can set the height perpendicular to the screen for the control to make the control not at the same height look hierarchical. Of course, we need to use the material design control to have this property. Here I use cardview.

We add a sliding listener to parallelaxrecyclerview, and make the following settings in the onscroled method:

The setcardelevation method is used to set the height of cardview. Here, the height of each item is 5dp higher than its previous item.

Differential of first term

Finally, we want to add a differential effect to the first item. This is also handled in the onscrolled method:

In this way, the sliding speed of the first item becomes half of the original. But this will also lead to a problem. Due to the change of the position of the control, when the control is reused, the position will be incorrect. Therefore, when setting the height, we can restore the position of the control:

This completes a recyclerview with a simple folding effect. It's OK.

Source address: parallelaxrecyclerview_ jb51.rar

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support 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
分享
二维码
< <上一篇
下一篇>>