Stop preloading pages in viewpager example

纵饮孤独 提交于 2019-12-13 08:25:59

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/36369413/stop-preloading-pages-in-viewpager-example

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!