。 OnClickListener 。 即便在网页上没有发生任何事情,也确实消耗了触角活动(如:),但没有任何机会开展奥恩克的活动。 这是非常不幸的。
As a workaround I extended a RelativeLayout
and put my WebView
inside of it. In the RelativeLayout
I ve overwritten onInterceptTouchEvent
and were looking for tap events. If a tap is detected then the RelativeLayout
s OnClickListener
is invoked with 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);
iii
public TapAwareRelativeLayout(Context context, AttributeSet attrs) {
super(context, attrs);
iii
@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();
iii
break;
case MotionEvent.ACTION_MOVE:
if (Math.abs(ev.getX() - mDownPosX) > MOVE_THRESHOLD_DP || Math.abs(ev.getY() - mDownPosY) > MOVE_THRESHOLD_DP) {
mMoveOccured = true;
iii
break;
iii
return super.onInterceptTouchEvent(ev);
iii
iii