Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
324 views
in Technique[技术] by (71.8m points)

android - ViewPager offscreen page limit

Is there a way to bypass the normal behavior of ViewPager and its offscreen page limit? My ViewPager contains four fragments, each containing a gridview of images. The problem I have is that on instansiation of the ViewPager, two fragments are created, which results in that about 20 images (about 10 per fragment) is downloaded/fetched from catch simultaneously. Is it possible to disable the offscreen page limit?

My goal is to only download images when a fragment is selected, or only when the user is hovering the image. One way to achieve this is to use the onPageSelected listener and set a flag, which tells the GridViewAdapter if it's allowed to download the image or not.

A second way that I can think of is to set a HoverListener on the ImageView, and only download the image on onHover, but that listener is only available in 4.0 and later.

Is there a better way to achieve this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Is it possible to disable the offscreen page limit?

No. It is already set to the minimum possible value: one page to each side of the viewed page. This is necessary to have the animation effects work -- you see parts of two fragments (original and new) at the same time.

My goal is to only download images when a fragment is selected, or only when the user is hovering the image.

Then load your grid with placeholder images, and do not load the real images until the page is changed.

Also, note that "hover" implies some sort of mouse or similar sort of pointer, which is not used on most Android devices.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...