Android recyclerview implements horizontal paging GridView effect example

Yesterday, the UI sister gave the requirements to show the horizontal pagination effect, and a part of the second page should be displayed by default to prompt the user that the horizontal can be slid. First, the effect drawing is shown:

Obviously, the first reaction to horizontally sliding paging is to use viewpager. After all, it is easy to achieve this effect by customizing viewpager. However, in practice, the current module is a holder in recyclerview. For performance, recyclerview must be used to reuse views as much as possible, and viewpager cannot be reused, so after consideration, You still need to use recyclerview to implement it.

Solution ideas

Since you intend to implement it with recyclerview, it is obvious that you can use gridlayoutmanager to handle the horizontal sliding list and preliminarily realize the effect of horizontal list and horizontal paging with 4 columns

The horizontal list effect is realized, but it does not meet the requirements of the design draft. The second page should display part by default, so we should think about and solve the problem from the horizontal direction. Since the second page should display part, if it displays 16dp, reduce the list width of the first page by 16dp, and the second page can be displayed on the first page. In the recyclerview adapter, the layout is displayed first:

In the onbindviewholder method, modify the margin

Let's see the effect

You can see that part of the second page can be displayed by default, and each subsequent page is displayed normally, without invading the previous page like the second page

summary

There are many ways to achieve this paging effect, but choosing the easiest and most efficient way is needed in development.

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
分享
二维码
< <上一篇
下一篇>>