Android scroll enables elastic sliding_ Example code for elastic sliding of list drop-down

This time I'm going to talk about using scroll to realize elastic sliding. I won't finish with only one example, because I'm also learning when writing the article. Let me finish it several times.

First, the previous code,

This code is the core of elastic sliding. The first function refers to slow sliding, but it does not have the actual function of sliding.

The five parameters of the startscroll function refer to the starting point X coordinate, starting point y coordinate, X displacement, y displacement, and the sliding time. The internal function of this function is to continuously calculate the values of X and Y coordinates in the sliding time. Then, because invalidate will call computescroll, this computescrolloffset function is to judge whether the current sliding is over. If it is not over, obtain the values calculated by the startscroll function through getcurrx and getcurry, and use scrollto to slide the corresponding positions, Because startscroll will calculate many times, that is, divide the sliding time into many segments, calculate the corresponding coordinates, and then give it to scrollto to realize sliding.

This is much like valueamplitude, which divides the time into many segments, calculates the corresponding value, and implements it many times at the same time.

I post a common elastic slide similar to the QQ message list. The drop-down here is not refreshed,

I won't talk about the painting and measurement of ViewGroup here. I'll talk about some things about obtaining functions and calculating coordinates.

It records the Y coordinate when the finger is pressed. When the finger moves, it follows the moving sub view. When the finger is raised, it uses the elastic sliding function smoothscrollbyscroller.

You will find why some calculated coordinates need to add a negative sign, because in our eyes, the displacement of our pull-down y coordinate is positive, but the system thinks this value is negative. I don't know the reason. If I know, please leave a comment and tell me.

Next time, write an example of elastic sliding with your fingers.

The above Android scroll realizes elastic sliding_ The example code of elastic sliding of list drop-down is all the content shared by Xiaobian. I hope it can give you a reference and 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
分享
二维码
< <上一篇
下一篇>>