Привет,
Я создал приложение, использующее ViewPager, и все страницы содержат WebView. Каждый веб-просмотр содержит серверные изображения, видео, mp3...
Настройки WebView
public Object instantiateItem(View collection, int position) {
.
.
.
final RelativeLayout imageLayout = (RelativeLayout)
inflater.inflate(R.layout.omb_webview_layout, null);
WebView webview = (WebView) imageLayout.findViewById(R.id.video_view);
ProgressBar pbImage = (ProgressBar) imageLayout.findViewById(R.id.progressBar1);
webview.requestFocus(View.FOCUS_DOWN);
webview.getSettings().setBuiltInZoomControls(false);
webview.getSettings().setSupportZoom(true);
webview.getSettings().setUseWideViewPort(true);
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setLoadWithOverviewMode(true);
webview.getSettings().setUseWideViewPort(true);
webview.setWebViewClient(new mWebViewClient());
webview.getSettings().setPluginsEnabled(true);
webview.clearCache(true);
webview.clearHistory();
if(Pbar != null) {
webview.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
Log.i(TAG, "webview loading progress : "+ progress);
if(progress == 100) {
try {
Pbar.setVisibility(ProgressBar.GONE);
} catch (Exception e) {
Log.e(TAG, "timer progress GONE : "+ progress,e);
}
}
});
}
Проблема в том, что когда страницы просматриваются, также выполняется эта строка
Log.i(TAG, "webview loading progress : "+ progress);
, что означает, что веб-просмотры загружаются в фоновом режиме. Если я прокручиваю 4 или более страниц, загружаются все веб-просмотры.
destroyItem(View collection, int position, Object o) {
Log.d("DESTROY", "destroying view at position sheetal " + position);
RelativeLayout view = (RelativeLayout)o;
WebView tmp = webviewDictionary.get(position);;
tmp.getSettings().setJavaScriptEnabled(false);
tmp.stopLoading();
if(tmp != null){
Log.i(TAG, "sheetal webview is destroyed " +position );
try {
tmp.onPause();
tmp.loadDataWithBaseURL("about:blank", "<html></html>","text/html", "UTF-8", null);
tmp=null;
// tmp.destroy();
}
catch (Exception e) {
Log.i(TAG, "webview destroyed Exception 0" ,e);
}
}
Как остановить фоновую загрузку, если страницы не видны? setOffscreenPageLimit(1)(означает 3 страницы назад,текущая,следующая),
В Viewpager 2 страницы (означает 1 позицию страницы) загружаются неправильно. Он показывает пустую белую страницу, как мне решить эту проблему?
Заранее спасибо