您可以使用
LinearLayout而不是
RelativeLayout拆分屏幕。只需将高度设置为0并将重量设置为1
GLSurfaceView并将
WebView两者都设置。在您的情况下,代码将为:
LinearLayout layout = new LinearLayout(this); // Use LinearLayout instead of RelativeglView = new GLSurfaceView(this);glView.setRenderer(this);glView.setZOrderMediaOverlay(false);// height is 0, weight is 1LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 1);layout.addView(glView, params);webView = new WebView(this);this.showWV(false); //handler message , i hide it in certain screen.webView.getSettings().setJavascriptEnabled(true);webView.getSettings().setLoadWithOverviewMode(true);webView.getSettings().setUseWideViewPort(true);// height is 0, weight is 1params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 1);layout.addView(webView, params);webView.loadUrl("http://stackoverflow.com");setContentView(layout);
或者,您可以使用
RelativeLayout硬编码的高度和宽度值:
RelativeLayout layout = new RelativeLayout(this); // Use LinearLayout instead of RelativeglView = new GLSurfaceView(this);glView.setRenderer(this);glView.setZOrderMediaOverlay(false);glView.setId(123); // set idRelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(640, 480);layout.addView(glView, params);webView = new WebView(this);this.showWV(false); //handler message , i hide it in certain screen.webView.getSettings().setJavascriptEnabled(true);webView.getSettings().setLoadWithOverviewMode(true);webView.getSettings().setUseWideViewPort(true);params = new RelativeLayout.LayoutParams(640, 480);params.addRule(RelativeLayout.BELOW, glView.getId()); // set WebView position is below GLSurfaceViewlayout.addView(webView, params);webView.loadUrl("http://stackoverflow.com");setContentView(layout);
UPD: 不带硬编码值,使用不可见视图:
RelativeLayout layout = new RelativeLayout(this); // Use LinearLayout instead of Relative// create a fake view with zero size and place it to center of RelativeLayoutView fakeView = new View(this); fakeView.setId(24736); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(0, 0);params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);layout.addView(fakeView, params);glView = new GLSurfaceView(this);glView.setRenderer(this);glView.setZOrderMediaOverlay(false);glView.setId(123); // set idparams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);params.addRule(RelativeLayout.ABOVE, fakeView.getId()); // set position is above fakeViewlayout.addView(glView, params);webView = new WebView(this);this.showWV(false); //handler message , i hide it in certain screen.webView.getSettings().setJavascriptEnabled(true);webView.getSettings().setLoadWithOverviewMode(true);webView.getSettings().setUseWideViewPort(true);params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);params.addRule(RelativeLayout.BELOW, fakeView.getId()); // set WebView position is below fakeViewlayout.addView(webView, params);webView.loadUrl("http://stackoverflow.com");setContentView(layout);
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)