2

I'd like to force my webview application in landscape ( largest mode), lock the aspect ratio so it'll always fill the screen, disable zoom ( when double tapping) & disable scrolling as well.

Here's what I've tried this far.

WebView b=(WebView)findViewById(R.id.webview);
        b.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
        b.setScrollbarFadingEnabled(false);
        b.getSettings().setJavaScriptEnabled(true);
        b.getSettings().setLoadWithOverviewMode(true);
        b.getSettings().setUseWideViewPort(true);
        b.getSettings().setBuiltInZoomControls(false);
        b.setPadding(0,0,0,0);b.setInitialScale(getScale());

  private int getScale(){
        Display display=((WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); 
        int width=display.getWidth();Double val=new Double(width)/new Double(800);
        val=val*100d;return val.intValue();
    }

Here's the rendering on my Galaxy note

Initial view: http://i.snag.gy/ol0Zh.jpg

View when double tapping on the screen ( the one I want as initial view): http://i.snag.gy/j6i3f.jpg

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
3ème pilier
  • 21
  • 1
  • 3

2 Answers2

1

To force it to landscape, in your manifest add android:screenOrientation="landscape" to the activity. That will prevent the activity from ever going portrait.

I wouldn't suggest disabling scrolling- what if your app doesn't fit on a smaller screen device? How will they see your content? You could shrink the display ratio, but that hurts people with vision problems (or even normal people if it becomes small enough). I'm only in my 30s and I zoom in on most websites to read the text more easily.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
  • yep scrolling, because the webview in an HTML5 canvas used to draw on it, with a mask, so preveting scrolling will keep them able to draw without ever scrolling .. – 3ème pilier Jul 14 '13 at 08:08
1

Set

webView.getSettings().setUseWideViewPort(false);

We can then manually set the scale. Refer to stackoverflow.com/a/3916700/519955 for this.

For landscape we can programmatically set it using:

myActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

We can make changes in the manifest too as answered earlier also.

Community
  • 1
  • 1
Ankit Aggarwal
  • 2,367
  • 24
  • 30
  • Thanks,currently, it's works for the width in portrait mode, but the scrolling is still there for the height .. and double taping still makes zooming .. not that conveninent for drawing .. – 3ème pilier Jul 14 '13 at 08:20
  • Currently, works for width with WideViewPort set as true, but not for the height .. there's where I get screwed .. – 3ème pilier Jul 14 '13 at 08:53
  • Here's the big deal on my galaxy note Initial view : http://i.snag.gy/ol0Zh.jpg View when double tapping on the screen ( the one I want as initial view ) : http://i.snag.gy/j6i3f.jpg – 3ème pilier Jul 14 '13 at 18:27
  • did you refer to the link I told you? I haven't tried on my own, but the comments there suggest that it works. After using that tell me exactly which all things don't work. – Ankit Aggarwal Jul 15 '13 at 07:52
  • `WebView browser = (WebView) findViewById(R.id.webview); browser.getSettings().setLoadWithOverviewMode(true); browser.getSettings().setUseWideViewPort(true);` @3eme pilier: Try only these lines. I saw in the question you posted that you tried other lines too. Try only these. This fixes size based on screen size. Tell me if it works :) – Ankit Aggarwal Jul 15 '13 at 07:54
  • Thanks for concern, Well obviously, I've tried many links on stack overflow, but none working, just double tapping on the screen makes zoom at a convenient level, see at the first screenshot ( on my note, we don't have the appropriate height ( close to it ), and emulating this double tap, will be a nice solution for me :) – 3ème pilier Jul 15 '13 at 08:20
  • oh so you want to disable zoom, and also set your initial display to the zoomed level? Sorry but I am not getting what is the problem remaining... – Ankit Aggarwal Jul 15 '13 at 09:29