Question : How do I get Web content to fit the window on the Android?

Hello,

I am using Android's documentation to simply have a website show on the device.  However, there is a lot of overflow when I display the webpage.  In other words, when the webpage displays (i.e. www.nyt.com) the page loads properly but with a lot of horizontal scroll.  Again in other words, the web page is too big for the window lol.  

I am using the 2.1 emulator.

I want to be able to fit the page in the aviable window (specifically, to get rid of the horizontal scroll bar) and have zoom controls enabled.

Below is the code I am using:  (I didn't attach the XML layout code, just the java)

Thank you!!!!!!!!!!!!!
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
package com.WebTest;



import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.view.KeyEvent;



public class WebTest extends Activity {
	
	WebView mWebView;
	
    public void onCreate(Bundle savedInstanceState) {
    	super.onCreate(savedInstanceState);    
    	setContentView(R.layout.web);    
    	mWebView = (WebView) findViewById(R.id.webview);    
    	mWebView.getSettings().setJavaScriptEnabled(true);    
    	mWebView.loadUrl("http://www.nyt.com");
    	mWebView.setWebViewClient(new HelloWebViewClient());
    	}
    private class HelloWebViewClient extends WebViewClient { 
    	@Override   
    	public boolean shouldOverrideUrlLoading(WebView view, String url) {  
    		view.loadUrl(url);      
    		return true;  
    		}
    }
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
    	if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) { 
    		mWebView.goBack();       
    		return true;    }  
    	return super.onKeyDown(keyCode, event);}
}

Answer : How do I get Web content to fit the window on the Android?

You could try
mWebView.zoomOut();

until you detect that the scroll width is lesser than the window width, but I'm not sure how to do that either. You can try these methods:
computeHorizontalScrollRange()
getWidth()
getMeasuredWidth()

http://developer.android.com/reference/android/view/View.html
Random Solutions  
 
programming4us programming4us