【发布时间】:2023-03-11 16:24:01
【问题描述】:
我有一个封装在 ScrollView 中的 LinearLayout(垂直)。 LinearLayout 是动态加载的,我想在滚动后到达页面底部时加载更多数据。
要知道何时到达页面底部,我重写了 ScrollView.onScrollChanged() 方法:
public class VerticalScrollView extends ScrollView {
private IVerticalScrollListener listener;
private LinearLayout list;
public VerticalScrollView(Context context, AttributeSet attributes) {
super(context, attributes);
}
public void setListener(IVerticalScrollListener listener) {
this.listener = listener;
}
@Override
protected void onScrollChanged(int x, int y, int oldx, int oldy) {
super.onScrollChanged(x, y, oldx, oldy);
if (list == null) {
list = (LinearLayout) findViewById(R.id.list);
}
final int bottom = list.getMeasuredHeight();
if (y >= bottom) { //never occures
listener.onPageBottomReached();
}
}
}
问题是“y”值总是(远)小于 LinearLayout 的高度。
为什么? 谢谢。
【问题讨论】:
-
也许你应该使用这个? How to Answer[1] [1]:stackoverflow.com/questions/10316743/detect-end-of-scrollview