3

我正在android.and我的代码在webview上工作

private final Handler handler = new Handler(this);
private WebView wv;


wv.getSettings().setBuiltInZoomControls(true);
wv = (WebView) v.findViewById(R.id.webView1);
            String data = "<html><link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" />"
                    + "<meta name=\"viewport\" content=\"width=device-width; initial-scale=1.0; min-scale=1.0; max-scale=3.0; \" />"
                    + "<body>"
                    + "<div style=\"text-align:center;width:100&#37;\">"
                    + "Murti"
                    + "</div> <br/><div>"
                    + "Touch and hold one of the customizable icons, then drag it to Remove. Touch ... The controls appear under your finger, and you can slide to a control and select it. ... Find apps with the biggest Wi-Fi data usage, then reduce their sync"
                    + "</div><br/><br/><br/><br/></body></html>";
            wv.loadDataWithBaseURL("file:///android_asset/", data,
                    "text/html", "UTF-8", null);
wv.setOnTouchListener(new OnTouchListener() {

                public boolean onTouch(View v, MotionEvent event) {
                    if (v.getId() == R.id.webView1
                            && event.getAction() == MotionEvent.ACTION_DOWN) {
                        handler.sendEmptyMessageDelayed(1, 500);
                    }
                    return false;
                }
            });

public boolean handleMessage(Message msg) {
    if (msg.what == 1) {
        Toast.makeText(MainActivity.this, "WebView clicked",
                Toast.LENGTH_SHORT).show();
        return true;
    }
    return false;
}

isuue 是,当我在 webview 上捏缩放而不是 zoomingcontroll 可见并且在那之后 ontouch 不工作。没有缩放 ontouch 工作正常。

4

1 回答 1

1

删除OnTouchListener并使用而不是它 dispatchTouchEvent

http://developer.android.com/reference/android/view/ViewGroup.html#onInterceptTouchEvent(android.view.MotionEvent) http://developer.android.com/reference/android/view/ViewGroup.html#dispatchTouchEvent( android.view.MotionEvent) http://developer.android.com/reference/android/view/ViewGroup.html#setDescendantFocusability(int)

创建您自己的扩展 WebView 和覆盖的类dispatchTouchEvent(MotionEvent ev)

public class MyWebView extend WebView {

    //constructor 

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        // code
        return super.dispatchTouchEvent(ev);
    }
}; 

如果您想了解更多关于 dispatcher 的信息,欢迎在这里How to use dispatchtoucheventhereonintercepttouchevent 和 ACTION_DOWN等等...

于 2013-09-27T12:39:52.313 回答