我正在尝试创建一个可以显示我的PhotosPhere
张照片的应用。问题是当我尝试从WebView
加载图像时,当我滚动照片时,它似乎不会滚动,而是跳转到我滚动的点。我在这里阅读使用getScrollX,Y
函数但我无法使它们工作,因为它们在我已经导入它们时似乎未被识别(import android.view
)。知道我怎么能让它正常工作吗?
import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
import android.view.accessibility.AccessibilityEvent;
public class BrowserView extends Activity {
String web;
WebView Browser;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
Browser = (WebView) findViewById(R.id.wbView);
// Use browser in application
Browser.setWebViewClient(new ourViewClient());
// Enable JavaScript
Browser.getSettings().setJavaScriptEnabled(true);
// Zoom Out
Browser.getSettings().setLoadWithOverviewMode(true);
Browser.getSettings().setUseWideViewPort(true);
Bundle gotBasket = getIntent().getExtras();
web = gotBasket.getString("key");
Browser.loadUrl(web);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
int temp_ScrollY = getScrollY();
scrollTo(getScrollX(), getScrollY() + 1);
scrollTo(getScrollX(), temp_ScrollY);
}
return super.onTouchEvent(event);
}
// Client
private class ourViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
}