public class ScrollBottomView extends ScrollView {
private ScrollViewToBottomListener scrollViewListener = null;
private OnScrollViewToBottomLiatener onScrollViewToBottomLiatener = null;
public ScrollBottomView(Context context) {
super(context);
}
public ScrollBottomView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public ScrollBottomView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void setScrollViewListener(ScrollViewToBottomListener scrollViewListener) {
this.scrollViewListener = scrollViewListener;
}
public void setOnScrollViewToBottomLiatener(OnScrollViewToBottomLiatener onScrollViewToBottomLiatener){
this.onScrollViewToBottomLiatener = onScrollViewToBottomLiatener;
}
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
super.onScrollChanged(l, t, oldl, oldt);
View view = (View) getChildAt(getChildCount() - 1);
int d = view.getBottom();
//根据距离判断是否滑到了底部
d -= (getHeight() + getScrollY());
// Log.e("---------->","d"+d);
if (d == 0) {
//滑到底部的监听
if (onScrollViewToBottomLiatener != null) {
onScrollViewToBottomLiatener.onScrollViewToBottomListener();
}
} else {
//滑动监听,可以根据滑动的距离做相应的事件,如返回顶部
if (scrollViewListener != null) {
scrollViewListener.onScrollChanged(this, l, t, oldl, oldt);
}
}
}
interface ScrollViewToBottomListener {
void onScrollChanged(ScrollBottomView scrollView,
int x, int y, int oldx, int oldy);
}
interface OnScrollViewToBottomLiatener {
void onScrollViewToBottomListener();
}
}
ScrollView滑到底部监听
最新推荐文章于 2020-08-31 17:07:41 发布