I’m using WebView in ViewPager to display images from internet. WebView is used because of it’s built in zoom controls. I want to enable my users to zoom images in pager, but when they swipe to the next image, to restore original zoom on previous image.
I tried few things, from which only one gives me the funcionality I desire, but it is not a good enough solution, because there is a blinking when swipeing through pages.
mPager.setOnPageChangeListener(new OnPageChangeListener(
) {
@Override
public void onPageSelected(int arg0) {
currImg = arg0;
//System.out.println("On page selected");
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
// TODO Auto-generated method stub
//System.out.println("On page scrolled");
}
@Override
public void onPageScrollStateChanged(int arg0) {
// TODO Auto-generated method stub
if(arg0 == 2) {
//mPager.getAdapter().
mPager.getAdapter().notifyDataSetChanged();
System.out.println("Notifying Data Set Changed " + mPager.getCurrentItem());
}
}
});
In ViewPager adapter I have overrided getItemPosition so it would return POSITON_NONE.
This is not a good solution because pages are refreshed on every swipe and there is no smooth transition between pages. Any suggestions are welcome.
This has shown to be a best way to revert the page to initial zoom state:
Than, in your adapter class you override getItemPosition method like this: