ScrollView滑到底部监听

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();
    }


}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值