ViewPager屏幕外的页面限制 [英] ViewPager offscreen page limit
问题描述
有没有一种方法可以绕过 ViewPager
和屏幕外的页数限制的正常行为?
我的 ViewPager
包含四个片段
,每个都包含一个的GridView
的图像。我的问题是,对instansiation在 ViewPager
,两个片段
创建,这将导致约20幅图像(约10%片段)下载/从抓获取同步。是否有可能禁用屏幕外页数限制?
我的目标是当一个片段
选择,或者只有当用户徘徊在图像只下载图像。实现这一目标的方法之一是使用 onPageSelected
监听器,并设置一个标志,它告诉 GridViewAdapter
如果它允许下载图片或没有。
这是我能想到的第二个方法是设置 HoverListener
在的ImageView
,只有下载图像上 onHover
,但该侦听器只在4.0及更高版本。
有没有更好的方式来实现这一目标?
是否有可能禁用屏幕外页数限制?
没有。它已被设置为最小的可能值:1页到观看页的一面。这是需要有动画效果的工作 - 你看到部分两个片段(原件及新)在同一时间
我的目标是仅下载图像时被选择的片段,或仅当用户悬停在图像
然后加载您的网格占位符图像,直到页面被更改不加载的实际图像。
另外,还要注意悬停意味着某种形式的鼠标或类似的排序指针,这是不是在大多数Android设备上使用。
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?
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.
这篇关于ViewPager屏幕外的页面限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!