我已经尝试了大约一个小时来检测我的 scrollView 是否到达了屏幕底部。由于涉及到 Android 的各种屏幕大小等问题,我不能简单地说当其 Y 坐标达到某个值时它就到达了底部,但是目前没有找到检测其是否到达底部的方法。
我相信这应该有一个简单的解决方案,比如用某个变量减去视图的高度之类的,但出于某些原因,它对我来说并不容易理解。如果您有任何想法,将不胜感激。谢谢。
我已经尝试了大约一个小时来检测我的 scrollView 是否到达了屏幕底部。由于涉及到 Android 的各种屏幕大小等问题,我不能简单地说当其 Y 坐标达到某个值时它就到达了底部,但是目前没有找到检测其是否到达底部的方法。
我相信这应该有一个简单的解决方案,比如用某个变量减去视图的高度之类的,但出于某些原因,它对我来说并不容易理解。如果您有任何想法,将不胜感激。谢谢。
试试这个:
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt)
{
// Grab the last child placed in the ScrollView, we need it to determinate the bottom position.
View view = (View) getChildAt(getChildCount()-1);
// Calculate the scrolldiff
int diff = (view.getBottom()-(getHeight()+getScrollY()));
// if diff is zero, then the bottom has been reached
if( diff == 0 )
{
// notify that we have reached the bottom
Log.d(ScrollTest.LOG_TAG, "MyScrollView: Bottom has been reached" );
}
super.onScrollChanged(l, t, oldl, oldt);
}
ScrollView
,然后重写从View
继承的onScrollChanged
方法。(View) getChildAt(getChildCount()-1);
是不必要的。 - drindt