WebViews在ViewPager不加载/渲染,直到页面显示 [英] WebViews in ViewPager are not loaded/rendered until page is shown
问题描述
我使用的是ViewPager许多WebViews,它是表示ePub格式。我的问题是,WebViews只是渲染/加载(我不是很确定)德恩及其相应的页面变得可见。在此之后的页面上不需要重新呈现,直到它从ViewPagerAdapter破坏。 其结果是,总是有一个白色的页面的一小会儿。我怎么能pre-使得它顺利滚动到下web视图(这是之前没有渲染)。
I use a ViewPager with many WebViews, it is for showing an ePub. My Problem is that the WebViews are just rendered/loaded (im not quite sure) wenn their corresponding page becomes visible. After this the page doesn't need to be re-rendered until it is destroyed from the ViewPagerAdapter. The consequence is that there is always a white page for a little while. How can i pre-render the page that it scrolls smooth to next webView (which was not rendered before).
这是我PagerAdapter:
This is my PagerAdapter:
public class MagazineReaderPagerAdapter extends PagerAdapter {
private MagazineReaderActivity activity;
private EpubDocument epub;
public MagazineReaderPagerAdapter(Context ctx, EpubDocument epub)
{
activity = (MagazineReaderActivity) ctx;
this.epub = epub;
}
@Override
public int getCount() {
return epub.getContentDocuments().size();
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
ReaderWebViewMulti view = new ReaderWebViewMulti(activity);
view.loadContentDocument(epub.getContentDocuments().get(position), epub);
((ViewPager) container).addView(view, 0);
return view;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view.equals(object);
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
((ViewPager) container).removeView((View) object);
}
}
ReaderWebViewMulti从的WebView IND扩展实现的方法loadContentDocument至极加载通过loadDataWithBaseURL的内容。
ReaderWebViewMulti extends from WebView ind implements a method loadContentDocument wich loads the content via loadDataWithBaseURL.
编辑: 在活性的OnCreate的setOffscreenPageLimit被设置为3
edit: At activity-oncreate the setOffscreenPageLimit is set to 3
viewPager.setOffscreenPageLimit(3);
要指出的是什么问题,我犯了一个小视频在 YouTube上
To point out what the problem is, i made a little video on YouTube
这是第二个4,你可以看到,每一页是刚刚呈现的时候已经是可见的。当我回去,一切都很好。
From second 4 you can see that every page is just rendered when it is already visible. When i go back everything is fine.
推荐答案
我有同样的问题,并通过禁用硬件加速Web视图固定它:
I had the same problem and fixed it by disabling hardware acceleration for the web view:
webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
请参阅<一href="http://stackoverflow.com/questions/8273327/webview-inside-viewpager-or-scrollview-weird-rendering-bug-on-android-3-0">WebView内ViewPager或滚动型 - Android电子奇怪的渲染错误3.0+
这篇关于WebViews在ViewPager不加载/渲染,直到页面显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!