ScrollView监听滑动到底部、顶部
2016-12-21 16:42
381 查看
package com.supoin.androidtextshow; import android.content.Context; import android.util.AttributeSet; import android.view.View; import android.widget.ScrollView; /** * 作者: kaifang * 时间: 2016/12/19 17:33 * 作用: */ public class ScrollViewExt extends ScrollView { private boolean isScrolledToTop; private boolean isScrolledToBottom; private IScrollChangedListener mScrollChangedListener; public ScrollViewExt(Context context) { super(context); } public ScrollViewExt(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public ScrollViewExt(Context context, AttributeSet attrs) { super(context, attrs); } public void setScrollViewListener(IScrollChangedListener scrollViewListener) { this.mScrollChangedListener = scrollViewListener; } @Override protected void onScrollChanged(int l, int t, int oldl, int oldt) { super.onScrollChanged(l, t, oldl, oldt); // We take the last son in the scrollview View view = getChildAt(0); if (view == null) return; int diff = (view.getBottom() - (getHeight() + getScrollY())); // System.out.println("diff= " + diff // + ",view.getBottom()=" + view.getBottom() // + ",this.getHeight()=" + getHeight() // + ",this.getScrollY()=" + getScrollY()); // if diff is zero, then the bottom has been reached isScrolledToBottom = false; isScrolledToTop = false; if (diff == 0) { isScrolledToBottom = true; if (mScrollChangedListener != null) mScrollChangedListener.onScrolledToBottom(); } else if (getScrollY() == 0) { isScrolledToTop = true; if (mScrollChangedListener != null) mScrollChangedListener.onScrolledToTop(); } } public boolean isTopEnd() { return isScrolledToTop; } public boolean isBottomEnd() { return isScrolledToBottom; } /** * 定义监听接口 */ public interface IScrollChangedListener { void onScrolledToBottom(); void onScrolledToTop(); } }
相关文章推荐
- Android ScrollView监听滑动到顶部和底部的两种方式
- Android ScrollView监听滑动到顶部和底部的两种方式(你可能不知道的细节)
- Android 自定义ScrollView嵌套滚动兼容,监听滑动状态:顶部、底部、停止、滑动中
- Android ScrollView监听滑动到顶部和底部的两种方式(你可能不知道的细节)
- Android - ScrollView 监听滑动停止,顶部还是底部?
- Android监听ScrollView或NestedScrollView滑动到顶部和底部
- [置顶] Android ScrollView监听滑动到顶部和底部的两种方式(你可能不知道的细节)
- 监听ScrollView滑动到最顶部和最顶部的完美实现
- 监听滑动到底部的ScrollView
- android listview 滑动到底部和监听滑动到顶部底部
- Android 监听 ScrollView 滑动到最底部,实现阅读协议,滑动到最低端显示已阅读按钮(2017版本)
- Android监听ScrollView滑动到顶端和底部
- Android ScrollView .顶部栏滑动透明度改变,底部栏滑到特定位置显示或隐藏效果
- 关于判断scrollview的滑动到顶部和底部的问题
- 关于ListView,GridView,ScrollView是否滑动到了顶部或者底部处理
- ScrollView监听停止滑动,判断是否滑到底部
- 监听ScrollView滑动到顶端和底部
- 判断ScrollView是否滑动到底部或顶部
- 监听ScrollView滑动到顶端和底部
- Android开发--------------WebView(二)之WebView的滑动底部顶部监听,加载进度条等设置