本文介绍了Android:获取WebView的滚动位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Android的新手.
I'm new to Android.
我只想简单地知道用户在页面上的滚动位置.当网页上的某个点出现在屏幕底部时,我想触发一个事件.但是此代码会导致异常.我知道WebView从View继承了 getScrollY()
.我执行不正确吗?
I would like to simply know where on a page the user has scrolled. When a certain point on the web page appears at the bottom of the screen, I want to trigger an event. But this code causes an exception. I know that WebView inherits getScrollY()
from View. Am I not implementing it correctly?
谢谢.
public class Scroll extends Activity {
public WebView webview;
public float yPos;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WebView webview = new WebView(this);
setContentView(webview);
webview.loadUrl("file:///android_asset/Scroll.html");
}
public boolean onTouchEvent(final MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_MOVE) {
yPos = webview.getScrollY();
Log.v("Scroll", "yPos = " + yPos);
}
return false;
}
}
推荐答案
例外是?
这是有关我的一个应用程序的WebView屏幕高度的注释:
And the exception is?
Here is a note on WebView screen heights from one of my apps:
// current position (top) = getScrollY();
// max position = getContentHeight();
// screen height = getHeight();
这篇关于Android:获取WebView的滚动位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!