amir
amir

Reputation: 85

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 >

enter image description here

What I want >

enter image description here

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);
                }


             } );

Upvotes: 2

Views: 560

Answers (1)

SuperFrog
SuperFrog

Reputation: 7674

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);

Upvotes: 2

Related Questions