Teach you to control the rhythm of recyclerview sliding

Recently, the landing page of PM upgrade and revision has a very strange interaction requirement, which is as follows:

The user can slide up and down infinitely on this page. However, during the pull-up sliding process, when the content is switched to another content, the new content will first attract the top, and then stop sliding to let the user know that he has slid to a new content area. There is no such constraint in the same content. The pull-down sliding process also has no such constraint.

Or if the user does not slide, but clicks on the new content area, it is also necessary to slowly suck the new content to facilitate the user to read.

As an Rd, I feel very painful. Since the demand is like this, as an omnipotent Rd, of course, I have to find a way to solve it.

First, select recyclerview as the sliding container. The difficulty is how to suck the new content page to the top and stop sliding during the sliding process. For recyclerview, after the user slides, the inertial sliding is finally realized through the flying method. Therefore, this method must be intercepted and some special operations must be done.

After trying the recyclerview's own methods and manager, we can't achieve slow ceiling. It seems that we can only rewrite some of them.

Let's look at a source code in linearsmoothscroller:

As you can see, snap_ TO_ Start means top or left. In this way, as long as you override the calculatedttofit method, you can achieve slow ceiling.

When will it be called? One is called when a new content area is clicked, and the other is to judge whether to switch the content area during the re sliding process. It's time to rewrite

However, you will find that if the item height value is estimated to be too small, it will lead to switching to the new content area immediately upon sliding, and the experience is still bad.

Sharp eyed people will find that I commented out a method in the mylinarlayoutmanger constructor earlier. This method is used to improve the sliding effect.

After calling this method, you will find that the effect is much better, but the default value is milliseconds_ PER_ Inch is 25F;

You will find that the effect seems better.

I hope this article is helpful for you to further understand recyclerview.

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