Android:WebApp同时使用WebView和Phonegap DroidGap

//有时候为了实现某些效果,我们需要增加webview来实现某些功能,比如固定的footer部分,为了保证中间部分的效果和性能,这部分可以采用独立的webview。
//下面的代码演示了如何在Phonegap项目中增加自己的webview控件。
public class Main extends DroidGap
{
	private static final String TAG = "Main";


	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
	
		WebView webView2 = new WebView(this);
		SetupWebView(webView2);
		super.loadUrl("file:///android_asset/www/t3.html",1000);

		webView2.loadUrl("file:///android_asset/www/t2.html");

	}

	/**
	 * Add a webview to the linearLayout The webView2 hold menubar.html
	 */

 private void SetupWebView(WebView webView2)  {   // 布局方向为垂直方向   this.root.setOrientation(LinearLayout.VERTICAL);

  CordovaWebView webView = new CordovaWebView(this);   CordovaWebViewClient webViewClient;   if (android.os.Build.VERSION.SDK_INT < 11 /*              * android.os.Build.VERSION_CODES              * .HONEYCOMB              */)   {    webViewClient = new CordovaWebViewClient(this, webView);   }   else   {    webViewClient = new IceCreamCordovaWebViewClient(this, webView);   }   // Set up web container   this.appView = webView;   this.appView.setId(100);   CordovaChromeClient webChromeClient = new CordovaChromeClient(this,     webView);   this.appView.setWebViewClient(webViewClient);   this.appView.setWebChromeClient(webChromeClient);   webViewClient.setWebView(this.appView);   webChromeClient.setWebView(this.appView);   // 第二个WebView占用屏幕的85%的高度,居于上方   LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(     ViewGroup.LayoutParams.FILL_PARENT, 0, 0.85f);   this.appView.setLayoutParams(params);

  // Add web view but make it invisible while loading URL   this.appView.setVisibility(View.INVISIBLE);   this.root.addView(this.appView);

  // 第二个WebView占用屏幕的15%的高度,居于下方   LinearLayout.LayoutParams params2 = new LinearLayout.LayoutParams(     ViewGroup.LayoutParams.FILL_PARENT, 0, 0.15f);   webView2.setLayoutParams(params2);   this.root.addView(webView2);

  setContentView(this.root);

  // Clear cancel flag   this.cancelLoadUrl = false;  }

}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值