在ViewPager示例中停止预加载页面 [英] Stop preloading pages in viewpager example

查看:422
本文介绍了在ViewPager示例中停止预加载页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找停止在Viewpager中预加载页面的示例源代码.通常,android viewpager会自动加载下一页和上一页.我的目标是使用viewpager,并且我希望在用户可见时在视图(页面中存在的视图)上显示动画.基本上,它是继续前面的 post .

I am looking for and example source code for stop pre-loading pages in viewpager. Normally android viewpager loads the next and previous page(s) automatically. My target is to use viewpager and I want to show animation on views(which are present in the pages) when it visible to the user. Basically it is to continue with the previous of post.

如果您能给我任何可行的示例(完整代码),它将非常友好.我发现了很多,但没有找到任何可行的实现. 谢谢你的帮助. 问候 比斯瓦吉特

If you can give me any working example(complete code) it will be so kind. I found so many but did not find any working implementation. Thanks for your help. Regards Biswajit

推荐答案

就像您已经知道无法阻止viewpagers加载一样.唯一的出路是使用此方法setUserVisibleHint将其添加到片段中,并在此方法中执行所有想要的动画

Like you already know there is no way of stopping viewpagers from loading . The only way out is to use this method setUserVisibleHint add this to your fragment, and do all the animation you want to in this method

@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
    super.setUserVisibleHint(isVisibleToUser);
    if (isVisibleToUser) {
        // animate here
     Log.e(TAG, "animate here");
    }else{
     Log.e(TAG, "fragment is no longer visible");
       // fragment is no longer visible
    }
}

仅当该特定选项卡对用户可见时,才会调用此选项.

This will be called only when that particular tab is visible to user.

这篇关于在ViewPager示例中停止预加载页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆