手勢(shì)識(shí)別和webview很多時(shí)候會(huì)出現(xiàn)沖突,一般我們用于接收GestureDetector對(duì)象的方法是OnTouchevent();,而在View組件占用了屏幕空間之后,這個(gè)方法就無(wú)效了篙程,只有換成 dispatchTouchEvent方法才有效她奥!
GestureDetector detector = new GestureDetector(this,this);
需要重寫(xiě)的方法
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
detector.onTouchEvent(ev);
webView.onTouchEvent(ev);//這幾行代碼也要執(zhí)行瓮增,將webview載入MotionEvent對(duì)象一下,況且用載入把哩俭,不知道用什么表述合適
return super.dispatchTouchEvent(ev);
}
下面是滑動(dòng)的識(shí)別,可以記錄一下
//滑動(dòng)
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
if(e1!=null){
float beginY = e1.getY();
float endY = e2.getY();
if(beginY-endY>60&&Math.abs(velocityY)>0){ //上滑
layout.setVisibility(View.GONE);
}else if(endY-beginY>60&&Math.abs(velocityY)>0){ //下滑
layout.setVisibility(View.VISIBLE);
}
}
return false;
}