问题描述
我使用的ViewPager的WebView显示来自互联网的图像。使用的WebView,因为它的内置缩放控制。我想启用我的用户寻呼机放大图像,但是当他们刷卡到下一个形象,恢复在previous形象原变焦。
我试过几件事情,从只有一个给我我渴望的funcionality,但它不是一个足够好的解决方案,因为有一个通过网页swipeing时闪烁。
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());
}
}
});
在ViewPager适配器我已经overrided getItemPosition所以它会返回POSITON_NONE。
这不是一个很好的解决方案,因为网页刷新每刷卡并没有页面之间没有平稳过渡。任何建议都欢迎。
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:
pager.setOnPageChangeListener(new OnPageChangeListener() {
public void onPageScrollStateChanged(int arg0) {}
public void onPageScrolled(int arg0, float arg1, int arg2) {}
public void onPageSelected(int arg0) {
System.out.println("onPageSelected -> arg0 = " + arg0);
if (currPage != arg0) {
mAdapter.notifyDataSetChanged();
currPage = arg0;
}
}
});
比,在你的适配器类重写getItemPosition方法是这样的:
Than, in your adapter class you override getItemPosition method like this:
@Override
public int getItemPosition(Object object) {
if (((ExtendedWebView) object).getScale() != webScale) {
return POSITION_NONE;
}
return POSITION_UNCHANGED;
}
这篇关于Android的:如何ZoomOut单页中ViewPager如果用户在放大呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!