4

When I use the following html:

img src="file:///sdcard/image1.jpg" width="100%" heighth="100%"

and use WebView.setBuiltInZoomControls(true), my webview is zoomable, but after I release my finger, the webview is zoomed back.

I guess it is because of width="100%" heighth="100%".

But image1.jpg is big, and at the beginning I want to show the whole image on screen. Later the user can zoom in/out.

Any solution or code sample?

blahdiblah
  • 33,069
  • 21
  • 98
  • 152
goodier
  • 395
  • 6
  • 18

3 Answers3

1

You have to calculate the scale that you need to use manually. PIC_WIDTH is the width of the webview.

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

Then use

WebView web = new WebView(this);
web.setPadding(0, 0, 0, 0);
web.setInitialScale(getScale());

Refer this LINK LINK

Community
  • 1
  • 1
Shankar Agarwal
  • 34,573
  • 7
  • 66
  • 64
0

I believe you're writing it wrong!

img src="file:///sdcard/image1.jpg" width="100%" heighth="100%"
img src="file:///sdcard/image1.jpg" width="100%" height="100%"

It is height and not what you've got there.

Lucifer
  • 29,392
  • 25
  • 90
  • 143
fjs
  • 131
  • 1
  • 7
0

If you are only showing a image off the Sd card are you sure you want to use a webview, or would it make more sense to use a ImageView. There are lots of examples/free code that Extend ImageView and provide this functionality.

A Webview may be the most bloated way of handling this functionality if all you want to do is display an image.

HaMMeReD
  • 2,440
  • 22
  • 29