Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Recyclerview to realize horizontal pagination in Android

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the Android how to use Recyclerview to achieve horizontal paging related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone in this Android how to use Recyclerview to achieve horizontal paging article will have a harvest, let's take a look at it.

Solution idea

Since we intend to implement it in Recyclerview, it is obvious that we can use GridLayoutManager to deal with the horizontal sliding list and initially achieve the effect of horizontal list, the horizontal paging effect with 4 columns.

Horizontal list effect is achieved, but did not meet the requirements of the design draft, the second page to show part of the default, then it is necessary to think from the horizontal direction to solve the problem, since the second page to show part of, if the display 16dp, then the first page of the list width will be reduced right margin 16dp, the second page can be displayed on the first page.

In the Adapter of Recyclerview, go to the layout first:

`

In the onBindViewHolder method, modify the margin

@ Overridepublic void onBindViewHolder (ItemHolder holder, int position) {if (null = = bean) {return;} RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams (ViewGroup.LayoutParams.MATCH_PARENT, DensityUtil.dip2px (86)); / / DensityUtil is the px to dp utility class int screenWidth = TCommonUtils.getScreenWidth (context); if (position)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report