Android webView 专注于图像的特定部分

Android webView focus on specific part of image

我的网络视图中有一张图片。图像太大,我启用了滚动,但问题是我想将默认视图(在执行滚动或缩放之前首先查看图像)设置为图像的特定部分。有什么想法吗?

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

结果>

我想要的>

答案>>

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


             } );

如果图像很大并且您想要显示特定部分,您可能想要缩放并滚动到特定部分。 例如,您可以做的是更改比例:

callUsView2.setInitialScale(some value which fits your needs);

如果您想更改位置,请滚动:

callUsView2.scrollTo(x,y);