Android development tutorial using threads to achieve smooth view scrolling example

Recently, I have been trying to do the pull-down refresh effect. After thinking for a long time, I came to the step of pulling the whole view down through the ontouch method. The next step is to pull it down and slide it back when I release my hand. After reading online for a long time, I didn't find a detailed example of pull-down refresh. I had to think about it slowly. Yesterday and today, after two days of research, the effect of rolling back after pull-down has finally been done today! happy. Now let's share my implementation methods and some experiences. I saw an example of a great God on the Internet and found that the scrollto (int, int) method of view was used in ontouch to scroll the whole view down. I tried to use settranslationy() to roll back the view. The first time it was ok, but after scrolling several times, the whole view actually reached a very "high" place, It takes a long distance to see the content. Therefore, rollback must also use the scrollto (int, int) method. However, the execution of scrollto (int, int) is instantaneous. The method name is to scroll to, which is actually "blink to" a certain position. Therefore, it needs to blink it step by step to make it look like it has rolled over

Because I'm going to run later, and there are not many key points to explain. I'll directly show you the code. The notes have been written. The key points will be mentioned separately. More detailed explanations and experience are waiting for me to refresh the drop-down one day.

Some key points:

1. The purpose of using thread is to call itself recursively, and scroll only a little in each run () method, which is determined according to the frame rate and interpolator.

2. The interpolator is actually a function (a function in Mathematics). It inputs floating-point numbers between 0-1 and outputs floating-point numbers between 0-1. The output curve depends on what interpolator it is. Decelerate is a deceleration interpolator. In the plane rectangular coordinate system, the x value changes uniformly and the Y axis changes more and more slowly.

3. The magnification (that is, multiplying by 1000) is to improve the accuracy, because it is found through practice that the result obtained by dividing the elapsed milliseconds by the whole animation cycle is 0.0 - > 0.0 - > 0.0 - > 0.0 - > 1.0 - > 1.0 - > 1.0 - > 2.0 - > 2.0 - > 2.0. Although it is a floating-point number, the accuracy remains inexplicably in single digits. After multiplying by 1000, There will be a uniform change of 0-1000. At this time, if 1000 is removed, the number of uniform changes between 0.000 and 1.000 can be obtained.

4. Another wonderful thing is that the values of motionevent. Gety () and scrollto (int, int) do not seem to be in the same coordinate system. This needs further analysis and research.

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