ViewPager 离屏页面限制 [英] ViewPager offscreen page limit
问题描述
有没有办法绕过ViewPager
的正常行为及其屏幕外页面限制?我的 ViewPager
包含四个 fragments
,每个包含一个 gridview
图像.我遇到的问题是,在 ViewPager
的实例化时,创建了两个 fragments
,这导致从 catch 下载/获取大约 20 个图像(每个片段大约 10 个)同时.是否可以禁用屏幕外页面限制?
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?
我的目标是仅在选择 fragment
或仅在用户悬停图像时下载图像.实现此目的的一种方法是使用 onPageSelected
侦听器并设置一个标志,该标志告诉 GridViewAdapter
是否允许下载图像.
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.
我能想到的第二种方法是在ImageView
上设置一个HoverListener
,只在onHover
上下载图片,但是该侦听器仅在 4.0 及更高版本中可用.
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?
推荐答案
是否可以禁用离屏页面限制?
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.
另外,请注意悬停"意味着某种鼠标或类似的指针,大多数 Android 设备上都没有使用.
Also, note that "hover" implies some sort of mouse or similar sort of pointer, which is not used on most Android devices.
这篇关于ViewPager 离屏页面限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!