在我的webview应用程序中,我正在尝试加载网页,我通过使用javascript从网页中删除一些项目进行了一些更改。现在剩下的部分主要是在网页的右侧。所以请帮我加载右侧的网页。我从一些教程得到了一个函数scrollTo()但我不明白使用它
MyWebViewActivity.java
package com.example.admin;
import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Picture;
import android.graphics.Point;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.WebSettings.ZoomDensity;
import android.webkit.WebView;
import android.webkit.WebView.PictureListener;
import android.webkit.WebViewClient;
@SuppressWarnings("deprecation")
public class MyWebViewActivity extends Activity {
private WebView webView;
@SuppressLint("SetJavaScriptEnabled")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
webView = (WebView)findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setBuiltInZoomControls(true);
//webView.getSettings().setDefaultZoom(ZoomDensity.FAR);
webView.setInitialScale(65);
Point Scroll=new Point(0,0);
Scroll.x=webView.getScrollX();
Scroll.y=webView.getScrollY();
webView.scrollTo(Scroll.x,Scroll.y);
webView.loadUrl("http://app.samworkshops.org/User_Reg.aspx");
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
StringBuilder builder = new StringBuilder("");
builder.append("javascript:document.getElementById('Image3').style.visibility= 'hidden';");
builder.append("javascript:document.getElementById('Image3').style.display = 'none' ;");
builder.append("javascript:document.getElementById('Image4').style.visibility= 'hidden';");
builder.append("javascript:document.getElementById('Image4').style.display = 'none' ;");
builder.append("javascript:document.getElementById('Image5').style.visibility= 'hidden';");
builder.append("javascript:document.getElementById('Image5').style.display = 'none' ;");
builder.append("javascript:document.getElementById('LnkVolunteer').style.visibility= 'hidden';");
builder.append("javascript:document.getElementById('LnkVolunteer').style.display = 'none' ;");
view.loadUrl(builder.toString());
}
});
}
}
答案 0 :(得分:0)
我认为这应该是这样的:
Point Scroll=new Point(0,0);
Scroll.x=150; // The new offset here.
Scroll.y=webView.getScrollY();
webView.scrollTo(Scroll.x,Scroll.y);
您可以使用此帖子:Android Webview - Webpage should fit the device screen来获取窗口宽度。然后一直向右滚动。