问题
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