Reputation:
I have a webview app, that uses js code files from assets. The issue I am having is that I have the game files in js that it takes up half the web browser. Now when I use the same as a webview in my app, it seems to be scrollable and half the view gets cut off from the screen which is scrollable. Is there a way I can restrict the boundaries of the webview and also force my webview to show the entire content of the webpage I am displaying? The following is my webview code:
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
Do I need to add this in a layout? If so, how do I go about it? Here is my java code:
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebView;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
WebView webview = (WebView)findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("file:///android_asset/index.htm");
}
}
Any changes required to the source files?
Thanks! Justin
Upvotes: 3
Views: 703
Reputation: 4651
try this:
WebView webview = (WebView)findViewById(R.id.webview);
webView.setInitialScale(1);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webView.setScrollbarFadingEnabled(false);
webview.loadUrl("file:///android_asset/index.htm");
UPDATE:
You can toggle Hardware Acceleration to make it faster.
& add this
webview.getSettings().setRenderPriority(RenderPriority.HIGH);
webview.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
Upvotes: 1