I am using a WebView to display an image that is in my resources, using a WebView because I need it to be zoomable. Dynamically I need to be able to draw points on the image, it is a map. To do this I am trying to put a canvas on top of the loaded image. The canvas would have the points drawn on it.
mWebView = (WebView)findViewById(R.id.webview);
mWebView.getSettings().setBuiltInZoomControls(true);
mWebView.loadUrl("file:///android_res/drawable/map.png");
Canvas c = new Canvas();
c.drawARGB(10, 0, 100, 12);//This is just random. It is where I would draw the points
mWebView.draw(c);
The last 3 lines in the code do not appear to do anything.
Is there a better way to go about drawing on top of a WebView? Is it even possible this way?
In you last line, you are giving it a new canvas (which will not have map.png loaded).
What you should do is:
Create a new class which extends WebView
override its onDraw() method, like:
public class MyWebView extends WebView{
#Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawPoint(yourPoint);
}
}
Make its variable:
MyWebView mWebView = new MyWebView(this);
mWebView.getSettings().setBuiltInZoomControls(true);
mWebView.loadUrl("file:///android_res/drawable/map.png");
add this view to your Main View of your layout.
myMainView.add(wv);
Done!
Is there a way to Pan a grid view to Horizontal Direction. I am implementing a grid view on a image. So whenever I zoom the image grid should also get to be zoom and pan in all direction, so i can select a specific area of the image.
I googled for panning of grid but not got satisfactory answers. please help me with some example code.
I too searched for some standard methods for zooming views other than image views but didn't find anything. So, I did a workaround for this and it works.
For zooming a view you can apply zoom animation on the view with fillAfter property enabled.
Here is how you can do this:
ScaleAnimation scale;
final float MAX_SCALE_FACTOR = 5f;
float currentScaleFactor = 1;
public static final long DURATION = 500;
GridView grid = (GridView)findViewById(R.id.grid);
public void scaleMyView()
{
if(currentScaleFactor <= MAX_SCALE_FACTOR)
{
DecelerateInterpolator interpolator = new DecelerateInterpolator();
scale = new ScaleAnimation(currentScaleFactor, currentScaleFactor*1.2f,
currentScaleFactor, currentScaleFactor*1.2f);
currentScaleFactor *= 1.2;
scale.setDuration(DURATION);
scale.setInterpolator(interpolator);
scale.setFillEnabled(true);
scale.setFillAfter(true);
grid.startAnimation(scale);
}
}
Here each time this method is called the view is scaled and the dimension is saved. You can decrease the animation duration to give the effect of instant zooming. Now you can call this method onPan or onTouch to apply zoom.
I hope this will help.
Is there any way to solve this? i don't want wo show the zoom control buttons in my webview,but it still supporting the zoom controls with mutiTouch.
thanks for your attention.
If you want have zoom in/out without zoom controls then use the below code(copied from here)
public class Main extends Activity {
private WebView myWebView;
private static final FrameLayout.LayoutParams ZOOM_PARAMS =
new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
Gravity.BOTTOM);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
myWebView = (WebView)findViewById(R.id.webView);
FrameLayout mContentView = (FrameLayout) getWindow().
getDecorView().findViewById(android.R.id.content);
final View zoom = myWebView.getZoomControls();
mContentView.addView(zoom, ZOOM_PARAMS);
zoom.setVisibility(View.GONE);
myWebView.loadUrl("http://www.almondmendoza.com");
}
}
I am trying to develop an application that displays lines of path of travel using openGL. I want to zoomin or zoomout the contents. Created a RelativeLayout and added the GLSurfaceView and ZoomControls to it. Now in the zoomControls.setOnZoomInClickListener i need to write how to zoom the view. For a view there are no zoom controls. Please help me if there is a way to zoom the view. Thank you..
mGLSView = new GLSurfaceView(this);
final RelativeLayout rl = new RelativeLayout(this);
ZoomControls zc = new ZoomControls(this);
zc.setOnZoomInClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
//// ??? WHAT TO DO WITH THE VIEW ?
}
});
zc.setVisibility(View.VISIBLE);
zc.bringToFront();
rl.addView(mGLSView);
rl.addView(zc);
setContentView(rl);
As far as I know, you cannot treat the GL Surface like a canvas and scale it.
So you will have to redraw the scaled version again using GL calls. An alternative would be to draw into FBO and render the scaled texture to the surface.
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