我的网页视图中有一张图片。图像是如此之大,我已启用滚动,但问题是我想在图像的特定部分设置默认视图(在进行滚动或缩放之前首先查看图像)。有什么想法吗?
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");
结果>
我想要的>
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);
}
} );
答案 0 :(得分:2)
如果图像很大并且您想要显示特定部分,则可能需要缩放并滚动到特定部分。 你可以做的是例如改变比例:
callUsView2.setInitialScale(some value which fits your needs);
如果您想更改位置,请滚动:
callUsView2.scrollTo(x,y);