v4包中的SwipeRefreshLayout包裹webview時,如果webview加載的html頁有固定表頭和上下滾動的表格,會造成滑動沖突,下滑會一直調用重新整理而不是html頁的資料滾動,解決方法是重寫webview。
public class WebView4Scroll extends WebView{
public WebView4Scroll(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()){
case MotionEvent.ACTION_DOWN:
if(this.getScrollY() <= 0)
this.scrollTo(0,1);
break;
case MotionEvent.ACTION_UP:
// if(this.getScrollY() == 0)
// this.scrollTo(0,-1);
break;
}
return super.onTouchEvent(event);
}
}
很簡單的重寫,每次按下的時候,如果在0,0坐标,讓它滾動到0,1,這樣就會告訴SwipeRefreshLayout他還在滑動,就不會觸發重新整理事件了。