3

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

1 Answers1

1

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);
Ahmed Ekri
  • 4,601
  • 3
  • 23
  • 42
  • perfect thanks, however, do you have any clue why its damn slow, any way to speed it up ? –  Aug 26 '13 at 18:54
  • on last question, how do i stop it from zooming everytime i click on the game , i tried webview.getSettings().setSupportZoom(false);, but it still zooms –  Aug 26 '13 at 19:12
  • thanks, do you happen to have any idea about this issue? it's pretty complicated so far:http://stackoverflow.com/questions/18382510/how-do-i-fix-the-password-username-authentication-in-my-code?noredirect=1#comment27114067_18382510 –  Aug 26 '13 at 19:26
  • ill try to answer it there – Ahmed Ekri Aug 26 '13 at 19:34