如果您真的想有所作为,我建议您使用我的方法:
我做了一个 JavaScript 可调用函数来创建另一个 WebView(“子 webview”),我会像 Iframe 一样使用它并填充内容,所以从 JS 应用程序我可以这样做:
insertWebView (x,y,w,h,"<div>.......</div>").
你必须做一些一次性的工作来稳定一种通信两个 webview 的方式,但你明白了。请在下面找到我的 insertWebView 函数的来源以获得灵感。
改进非常棒,因为这些微小的 iframe-webview 不仅表现出色,而且像发光的过度滚动、多点触控(现在它们是不同的 webviews!)等提供了接近原生的体验。
我还做了一个扩展,在 webviews 之间使用原生拖放。
可能它在内存方面效率不高,但就用户体验而言,相信我值得一千次努力。
祝你好运!
public void insertWebView(int code, int x0, int y0, int w, int h, String url, int vertical, String initContent, String params, int alpha, int rot, int screenId) {
PlasmaWebView webview1 = getWebView(code);
if (webview1 != null) {
if (Conf.LOG_ON) Log.d(TAG, "WEBVIEW: Reusing webview " + code + " at " + x0 + "," + y0 + "," + w + "," + h + " vertical " + vertical+", rot="+rot);
webview1.setVerticalScrollBarEnabled(vertical == 1);
webview1.setHorizontalScrollBarEnabled(vertical != 1);
webview1.move(x0, y0, w, h, Funq.this);
if ((alpha>0) && (alpha<100)) webview1.setAlpha((float)alpha/100);
webview1.setRotation((float)rot/10);
webview1.handleTemplateLoad(url, initContent);
return;
}
if (Conf.LOG_ON) Log.d(TAG, "WEBVIEW: Insert webview " + code + " at " + x0 + "," + y0 + "," + w + "," + h + " vertical " + vertical + " url " + url+" alpha "+alpha+", rot="+rot);
webview1 = new PlasmaWebView(Funq.this.getBaseContext(), code, vertical==1, useHardware, jvs, screenId);
if ((alpha>0) && (alpha<100)) webview1.setAlpha((float)alpha/100);
webview1.setRotation((float)rot/10);
RelativeLayout.LayoutParams p=webview1.createLayout(x0, y0, w, h, Funq.this);
layerContainer.addView(webview1, p);
webview1.handleTemplateLoad(url, initContent);
}