【android】判断HorizontalScrollView/ScrollView滑到最左/上和最右/下
16lz
2021-01-23
HorizontalScrollView:
@Override protected void onScrollChanged(int l, int t, int oldl, int oldt) { // TODO Auto-generated method stub super.onScrollChanged(l, t, oldl, oldt); int maxScrollX = getChildAt(0).getMeasuredWidth()-getMeasuredWidth(); //滑到最左 if (getScrollX() == 0 ) { }else if (getScrollX() == maxScrollX) { //滑到最右 }else { //滑到中间} }
ScrollView:
只需将上面代码中的ScrollX改为ScrollY,MeasuredWidth改为MeasuredHeight即可
参考http://stackoverflow.com/questions/9597943/how-to-detect-that-the-horizontalscrollview-has-reached-an-end
更多相关文章
- android 100行代码实现 仿苹果滑动选择器WheelView
- Android之图文混排 (二)源代码
- 一段Android实现应用下载并自动安装apk包的代码
- 36个Android开发常用代码片段
- Android 进阶的小技巧整理(整理自第一行代码)
- Android 通过代码设置着色图片
- android典型代码系列(五)------deviceadmin步骤
- 用代码如何检测一个android程序是否在运行