Android simply realizes unlimited scrolling and automatic scrolling viewpager
We often see a viewpager that can automatically scroll and scroll infinitely in the application. Baidu and Google also have many tutorials on this aspect, but it feels a little troublesome and the packaging is not very thorough. So try to encapsulate a better viewpager
The effects are as follows:
Let's briefly talk about the implementation idea. To realize infinite scrolling, you need to do some tricks on pageradapter, and set the return value of getcount function of pageradapter to integer.mxa_ Value can realize infinite scrolling to the right, but what about infinite scrolling to the left? At the beginning, set a very large value for setcurrentitem (so large that you scroll to the left for 10000 years, there is still something)
Then the other is the cursor at the bottom:
The cursor at the bottom uses a custom view: just draw a background and then draw a highlighted cursor
R.layout.layout_ recommend_ Item layout:
Another is to realize automatic scrolling, which is to listen to the functions in onpagerchangelister and send an interface switching message by using the handler when the viewpager state changes:
Overall Code:
Then an interface call is provided:
The imageload library is used to load images:
usage method
The above is the viewpager that Xiaobian introduced to you. Android simply realizes infinite scrolling and automatic scrolling. I hope it will be helpful to you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!