Android 判断Webview 的水平滚动
来源:互联网 发布:网络歌曲男人伤感情歌 编辑:程序博客网 时间:2024/05/15 20:23
I found a solution which work for me, I check the source code of class WebView in 2.3 API and find how to do it with a 2.1 API. Maybe it can work with older API:
public class CustomWebView extends WebView { private float oldX; // indicate if horizontal scrollbar can't go more to the left private boolean overScrollLeft = false; // indicate if horizontal scrollbar can't go more to the right private boolean overScrollRight = false; // indicate if horizontal scrollbar can't go more to the left OR right private boolean isScrolling = false; public CustomWebView(Context context) { super(context); // TODO Auto-generated constructor stub } public CustomWebView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // TODO Auto-generated constructor stub } public CustomWebView(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub } @Override public boolean onTouchEvent(MotionEvent event) { // width of the vertical scrollbar int scrollBarWidth = getVerticalScrollbarWidth(); // width of the view depending of you set in the layout int viewWidth = computeHorizontalScrollExtent(); // width of the webpage depending of the zoom int innerWidth = computeHorizontalScrollRange(); // position of the left side of the horizontal scrollbar int scrollBarLeftPos = computeHorizontalScrollOffset(); // position of the right side of the horizontal scrollbar, the width of scroll is the width of view minus the width of vertical scrollbar int scrollBarRightPos = scrollBarLeftPos + viewWidth - scrollBarWidth; // if left pos of scroll bar is 0 left over scrolling is true if(scrollBarLeftPos == 0) { overScrollLeft = true; } else { overScrollLeft = false; } // if right pos of scroll bar is superior to webpage width: right over scrolling is true if(scrollBarRightPos >= innerWidth) { overScrollRight = true; } else { overScrollRight = false; } switch (event.getAction()) { case MotionEvent.ACTION_DOWN: // when user touch the screen // if scrollbar is the most left or right if(overScrollLeft || overScrollRight) { isScrolling = false; } else { isScrolling = true; } oldX = event.getX(); break; case MotionEvent.ACTION_UP: // when user stop to touch the screen // if scrollbar can't go more to the left OR right // this allow to force the user to do another gesture when he reach a side if(!isScrolling) { if(event.getX() > oldX && overScrollLeft) { // left action } if(event.getX() < oldX && overScrollRight) { // right actio } } break; default: break; } return super.onTouchEvent(event); }}
- Android 判断Webview 的水平滚动
- Android webview解决图片过大出现水平滚动条的问题
- android 水平滚动条的使用
- Android 自定义水平滚动的容器
- Android 水平滚动
- android 水平滚动 HorizontalScrollView
- Android------水平滚动
- android textview 水平滚动
- Android-判断WebView是否已经滚动到页面底端
- Android--判断WebView是否已经滚动到页面底端
- Android : 判断WebView是否已经滚动到页面底端
- Android禁止WebView滚动的方法
- Android实现真正的禁止WebView滚动
- 水平滚动的textview
- gridview 的水平滚动
- android 监听 webview 滚动
- android 禁止webview滚动
- android水平循环滚动控件
- javascript中文比较方法——localeCompare() 方法
- 算法导论1.1
- VoIP基本概念:H.323协议简介
- POJ-1204-Word Puzzles
- Bellman-Ford 算法实现单源最短路径
- Android 判断Webview 的水平滚动
- IT程序员不得不知道的程序出现的错误类型
- Oracle10G多台服务器同步高级复制
- 计算器
- Windows Update 错误 80070003
- Android ViewPager 中嵌套webview 的滚动处理
- CSS3 PIE 让 IE6-8 支持部分 CSS3 新特性
- Windows+Python+Apache+wsgi
- 第六章 访问权限控制