Detailed analysis of Android Viewpager infinite loop scrolling picture

Source: Internet
Author: User

Due to the recent busy project, there is no time to update the blog, so take advantage of the Sunday in the room to the recent projects encountered in the technical summary. Recently in the project to do a Viewpager unlimited scrolling picture needs, in fact, Baidu has a lot of examples, but most of them, although the implementation, but not clear, I looked at a lot of information, I know Position/list.size (). But how to use it, I still do not understand. I later saw the Baidu engineer Ningyugang the implementation of the circular ad bit components suddenly understand the principle of infinite scrolling. Summarized as follows:

1. To write the return banner_size in the int getcount () method. This banner_size is a well-defined constant and it is better to define a larger one, such as 1000, 10000. What I used to mean by the return value of this method is that I don't quite understand. If it is written as return list.size () then understood. I think this is more likely to return the list because the Viewpager image is returned from the server side, and the number and address change at any time. Return a larger value such as 1000 is Viewpager represents this viewpager you can slide it 1000 down. If you only have 3 pictures, you keep sliding, so that the 3 pictures back and forth, that is, let position 012012012..... Isn't that the infinite loop you want to slide? So how does this let it slip through the loop? Then it is necessary to implement the Object Instantiateitem (viewgroup container, int position) method.

2. Object Instantiateitem (viewgroup container, int position)

If it is viewpager to display the image returned by the server, you want to put the download network image code here to write, such as the use of Imagerloader download pictures (by the way, it is very convenient to use the framework, I really want to send an e-mail thank the author of this framework, writing is great, For the benefit of the world's coder Ah, do not know, with a scare jump). Well, to think that position is 0 1 2 0 1 2 cycle, then you have to write position=position% list.size () (I don't think position%banner_size, otherwise the array subscript out of bounds, Ningyugang seems to have written the wrong) right The postion of the edge is the position of the GetCount () return value above. For example, setting 1000, then position is 0 1 2 3 4 .... 1000, so the left side of the position value is 0 1..list.size () loop.  The size of the picture collection is 3, then 0 1 2 0 1 2 ..... Instead, the following table showing the picture is the one that always loops at 0 1 2. So that when you swipe to the four screen, it shows the first, sliding five screen is the second picture, sliding the sixth screen is the third picture, so and so on. This will allow the loop to slide, but is it really an infinite loop? If you really idle all right, keep slippery, slippery, slippery ah, certainly will at some time cannot slide. The purpose of this is to make you feel that the infinity is slipping. And my experience is instantiateitem like Baseadpter's in the GetView () method to control each item of the ListView. Viewpager display pictures actually use ImageView to display each picture, this is the same as the ListView display Picture list.

Detailed analysis of Android Viewpager infinite loop scrolling picture

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.