我正在开发一个在线杂志应用程序。它从服务器下载50到100个html5文件,并将其存储在SD卡上,并将此html5文件显示为杂志页面。我使用了gallery小部件来加载html页面,它可以满足我的要求。
但有些问题,例如在画廊上加载html似乎很慢,并且在刷页时页面移动速度仍然很慢。我的代码如下所示
public View getView(int position, View convertview, ViewGroup parent) {
try{
vi = convertview;
final int loctn = position;
if (convertview == null)
vi = inflater.inflate(R.layout.contentsadapter, null);
WebView webview=(WebView)vi.findViewById(R.id.webView1);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl(pages.get(loctn));
webview.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override
public boolean shouldOverrideKeyEvent(WebView view, KeyEvent event) {
if ((event.getKeyCode() == KeyEvent.KEYCODE_BACK)
&& view.canGoBack()) {
view.goBack();
return true;
}
return super.shouldOverrideKeyEvent(view, event);
}
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
/*Intent intent = new Intent(Femi9Activity.this,
SplashScreen.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Femi9Activity.this.startActivity(intent);*/
}
});
webview.getSettings().setDomStorageEnabled(true);
// Set cache size to 8 mb by default. should be more than enough
webview.getSettings().setAppCacheMaxSize(1024 * 1024 * 8);
webview.getSettings().setAllowFileAccess(true);
webview.getSettings().setAppCacheEnabled(true);
webview.setOnTouchListener(new OnTouchListener(){
public boolean onTouch(View v, MotionEvent event) {
gallery.onTouchEvent(event);
return false;
}
});
}catch(Exception e){
}finally{
}
return vi;
}
}
所以问题是
答案 0 :(得分:1)
您可以使用ViewPager
代替Gallery
。