Hi,
I am having issue while showing a WebView in an activity in the middle of the screen.
I have an activity and I want to show a webview in the center of screen. My activity is transparent so background activity will be visible. Whenever I try to create a webview and add it to activity using setContentView(webview) it always shows the view on the top left corner of the screen. Is their a way to workaround this?I am trying to do this via pure code only. Here is my code.
protected void onCreate(Bundle savedInstance) {
//some initialization stuff
LinearLayout ll = new LinearLayout(activity);
ll.setOrientation(LinearLayout.VERTICAL);
ll.setGravity(Gravity.CENTER_HORIZONTAL);
ll.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT));
ll.setBackgroundColor(android.R.color.transparent);
ll.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL); //added after suggestion
webView = new WebView(this);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.loadUrl("http://www.google.com");
ll.addView(webView);
webView.setBackgroundColor(android.R.color.transparent);
setContentView(ll);
}
.