我正在尝试制作一个应用程序,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;
}
}
}