Set zoom for Webview - android

I have a WebView and 2 urls to open it it. What I want to do is, when i set a zoom level for 1st url, and then i go to 2nd url, it should also have the same zoom level. Right now, the zoom level resets for both.
Thanks,
Farha

this will be applicable in this scenario i believe
mWebView.setInitialScale(ZOOM_LEVEL);
where ZOOM_LEVEL for example can be
25 for 25%
150 for 150%

use the webSettings class
webview.getSettings().setDefaultZoom(WebSettings.ZoomDensity.FAR);
Notice that although webSettings is available since API Level 1, WebSettings.ZoomDensity is available since API Level 7. Works well for all device resolutions.
Also, in order to enable zoom on the webView, add the following code:
webView.getSettings().setBuiltInZoomControls(true);

setDefaultZoom is deprecated.
webview.getSettings().setDefaultZoom(WebSettings.ZoomDensity.FAR);
So instead of that you can use like below,
webview.setInitialScale(1);
webview.getSettings().setLoadWithOverviewMode(true);
webview.getSettings().setUseWideViewPort(true);
This help you to remove
setDefaultZoom(WebSettings.ZoomDensity.FAR).

Before you leave the first page, use
int scale = 100 * webView.getScale();
Then after you load the second page, use
webView.setInitialScale( scale );

#John gave the right idea, but one command is enough, since you can get and set before the page shows:
private class MyWebViewClient extends WebViewClient {
public void onPageFinished(WebView view, String url) {
view.setInitialScale((int)(100*view.getScale()));
}
}
then just set this as your WebView's client:
webview.setWebViewClient(new MyWebViewClient());

You can set the zoom to 0.1f
mWebView.zoomBy(0.1f);

try this thing
int default_zoom_level=100;
Point Scroll=new Point(0,0);
webview1.setInitialScale(default_zoom_level);
webview1.loadData("url");
After doing zoomIn/ZoomOut or Scrolling.Since Scale may be get to change so calculate scale level and scrolling along X and Y Axis.
int current_scale_level=(int)webview1.getScale()*100;
Scroll.x=webview1.getScrollX();
Scroll.y=webview1.getScrollY();
then before loading of next webview do this
webview2.setInitialScale(current_scale_level);
webview2.loadData("url");
webview2.scrollTo(Scroll.x,Scroll.y);

I found this blog helpful:
It will help you set initial zoom level and on seek-change content of webview resizes
// Set the initial progress of seek bar
mSeekBar.setProgress(mWebView.getSettings().getTextZoom()/25);
// Set a change listener for seek bar
mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
/*
public abstract void setTextZoom (int textZoom)
Sets the text zoom of the page in percent. The default is 100.
Parameters
textZoom : the text zoom in percent
*/
// Zoom the web page text
// We will allow text zooming 25% to 300%
mWebView.getSettings().setTextZoom(i*25);
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
http://android--code.blogspot.in/2016/01/android-how-to-change-webview-text-size.html

Zooming of WebView can be controlled programatically by zoomIn() and zoomOut() methods

Related

Android webView focus on specific part of image

I have an image inside of my web view. The image is so big and I've enabled scrolls but the problem is that I want to set default view (first look on image before doing scroll or zoom ) to specific part of image. Any idea ?
WebView callUsView2= (WebView) rootView.findViewById(R.id.callUsView2);
WebSettings callUsView2Setting = callUsView2.getSettings();
callUsView2Setting.setBuiltInZoomControls(true);
callUsView2Setting.setDisplayZoomControls(true);
callUsView2.setVerticalScrollBarEnabled(true);
callUsView2.setHorizontalScrollBarEnabled(true);
callUsView2.loadUrl("file:///android_asset/map.png");
Result >
What I want >
ANSWER >>
callUsView2.setWebChromeClient(new WebChromeClient(){
#Override
public void onProgressChanged(WebView view, int progress) {
if ( view.getProgress()==100) {
// I save Y w/in Bundle so orientation changes [in addition to
// initial loads] will reposition to last location
jumpToY(1000 , 1800 );
}
}
private void jumpToY (final int xLocation , final int yLocation ) {
callUsView2.postDelayed( new Runnable () {
#Override
public void run() {
callUsView2.scrollTo(xLocation, yLocation);
}
}, 300);
}
} );
If the image is big and you want to show a specific part, you may want to zoom and scroll to a specific part.
What you can do is for example change the scale:
callUsView2.setInitialScale(some value which fits your needs);
and scroll if you wish to change the position:
callUsView2.scrollTo(x,y);

how control scroll in webview (Android)

I have an image with low resolution, this image should be shown in a web-view. User can scale the image, Then i need to replace image with higher resolution after the web-view got the zoom-in event.
I should load image and scroll to same x and y with higher resolution. Any idea? is it possible to do it smoothly?
I have tried this but it is not working
wv.scrollTo(x,y);
try this
private Runnable mScrollDown = new Runnable()
{
public void run()
{
WebView webview = (WebView)findViewById(R.id.web_url);
webview.scrollBy(0, scrollSpeed);
mHandler.postDelayed(this, 200);
}
};

Android WebView smooth scroll

I'm trying to scroll a webview programaticly but I'm having some problems. webView.setScrollY() doesn't give me an animation an webView.flingScroll() seems to behave diffrently depending on how long the page is. What is the best way to do this?
You can scroll using ObjectAnimator by providing current position of webview like this API 11+
ObjectAnimator anim = ObjectAnimator.ofInt(webView, "scrollY", webView.getScrollPositionY(), 0);
anim.setDuration(500).start();
You can use webView.scrollTo(x, y) method. However, this will scroll instantly.
There is no method available for WebView to scroll with animation. If you really have to do it, put the WebView into ScrollView and then you can use e.g. smoothScrollBy etc.
private final Property<WebView, Integer> WEBVIEW_SCROLL = new Property<WebView, Integer>(Integer.class, "") {
#Override
public Integer get(WebView object) {
return object.getScrollY();
}
#Override
public void set(WebView object, Integer value) {
object.scrollTo(object.getScrollX(), value);
}
};
ObjectAnimator.ofInt(mWebView, WEBVIEW_SCROLL, targetY).setDuration(duration).start();
It's work for me~,you can try this~

How do I scroll a WebView to a specific point on Android

I have a WebView and I would like my app to find a mark on the text(I'm using the symbol ► in the html).I have lots of html files each with almost 10 of these markings.
I have done it pretty easily with TextView doing this:
int offset=texto.indexOf("SPECIFIC MARKING ON TEXT");
final int line = textview.getLayout().getLineForOffset(offset);
final int y = textview.getLayout().getLineTop(line); // e.g. I want to scroll to line
final ScrollView s = (ScrollView)findViewById(R.id.ScrollView01);
s.post(new Runnable() {
#Override
public void run() {
s.smoothScrollTo(0, y);
}
});
But how do I accomplish that on Webview ?
The reason I use Webview is due to better text formatting.
In fact, it's even simpler with a WebView. You can use the findAll method for the first occurrence, then findNext(true) for the following markers. The view will automatically scroll to the requested text.

Recommendations for a pannable-zoomable view of a single large image?

I want to display a large-ish image, around 800 x 800 pixels. I'd like to be able to pan it in all four directions by dragging with a finger. I'd also like to be able to zoom in and out. I need to be able to know the pan values and zoom values, because I have to draw small text strings at certain locations over the image.
For example, if the pan is 100 pixels to the right, I need to know that so I can add that offset to all my elements.
Wondering what a good way to do this is. Should I implement it myself in the paint method within a View I implement? Is there some other standard method of doing it? It's essentially like a google maps view, only one large tile, but I have to draw my pins on top of it with pan and zoom,
Thanks
Hi guys i tried some months ago with no success, at last i just load the images inside a webview enabling the zoom controls and i was able to do the panning of my image...
public class PhotoZoom extends Activity {
private static final FrameLayout.LayoutParams ZOOM_PARAMS =
new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
Gravity.BOTTOM);
private WebView PhotoZoom;
private long lastTouchTime = -1;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.photo_zoom);
PhotoZoom = (WebView) findViewById(R.id.PhotoZoom);
PhotoZoom.setBackgroundColor(Color.BLACK);
Bundle bundle = getIntent().getExtras();
String Photoname = bundle.getString("URLPhoto");
PhotoZoom.loadUrl("content://com.jorgesys.pan/sdcard/myimages/" +fotoname);
WebSettings webSettings = PhotoZoom.getSettings();
webSettings.setSavePassword(false);
webSettings.setSaveFormData(false);
webSettings.setJavaScriptEnabled(true);
webSettings.setSupportZoom(true);
FrameLayout mContentView = (FrameLayout) getWindow().getDecorView().findViewById(android.R.id.content);
View zoom = PhotoZoom.getZoomControls();
mContentView.addView(zoom, ZOOM_PARAMS);
zoom.setVisibility(View.VISIBLE);
}
}

Categories

Resources