转自:http://www.trinea.cn/android/on-bottom-load-more-scrollview-impl/
1、判断是否已经滚动到顶部或底部,代码如下:
|
private
void
doOnBorderListener
(
)
{
if
(
contentView
!=
null
&&
contentView
.
getMeasuredHeight
(
)
<=
getScrollY
(
)
+
getHeight
(
)
)
{
if
(
onBorderListener
!=
null
)
{
onBorderListener
.
onBottom
(
)
;
}
}
else
if
(
getScrollY
(
)
==
0
)
{
if
(
onBorderListener
!=
null
)
{
onBorderListener
.
onTop
(
)
;
}
}
}
|
滚动到顶部判断:getScrollY() == 0
滚动到底部判断
|
View
contentView
=
getChildAt
(
0
)
;
contentView
.
getMeasuredHeight
(
)
<=
getScrollY
(
)
+
getHeight
(
)
;
|
其中getChildAt表示得到ScrollView的child View,因为ScrollView只允许一个child view,所以contentView.getMeasuredHeight()表示得到子View的高度, getScrollY()表示得到y轴的滚动距离,getHeight()为scrollView的高度。当getScrollY()达到最大时加上scrollView的高度就的就等于它内容的高度了啊~