我正在使用Html字符串加载Web视图,我想在用户点击Web视图时显示导航按钮,我尝试使用onTouch监听器,在滚动和点击时触摸事件引发但 我想捕获单击/ clickEvent,而不是滚动事件触摸...,我为WebView和LinearLayout实现了SetOnClickListener,它们都没有为我工作 任何关于此的帮助
WebView
不支持OnClickListener
.而且即使网页上没有任何反应,它也会消耗触摸事件,因此祖先视图(如您的LinearLayout
)没有任何机会产生OnClick事件.非常不幸.
作为一种解决方法,我扩展了一个RelativeLayout
并将其置于WebView
其中.在RelativeLayout
我已经覆盖onInterceptTouchEvent
并正在寻找轻敲事件.如果检测到点击,则调用RelativeLayout
's' .OnClickListener
performClick()
public class TapAwareRelativeLayout extends RelativeLayout { private final float MOVE_THRESHOLD_DP = 20 * getResources().getDisplayMetrics().density; private boolean mMoveOccured; private float mDownPosX; private float mDownPosY; public TapAwareRelativeLayout(Context context) { super(context); } public TapAwareRelativeLayout(Context context, AttributeSet attrs) { super(context, attrs); } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { final int action = ev.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: mMoveOccured = false; mDownPosX = ev.getX(); mDownPosY = ev.getY(); break; case MotionEvent.ACTION_UP: if (!mMoveOccured) { // TAP occured performClick(); } break; case MotionEvent.ACTION_MOVE: if (Math.abs(ev.getX() - mDownPosX) > MOVE_THRESHOLD_DP || Math.abs(ev.getY() - mDownPosY) > MOVE_THRESHOLD_DP) { mMoveOccured = true; } break; } return super.onInterceptTouchEvent(ev); }
}