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;
}

問題は、表示されている zoomingcontroll よりも webview でズームをピンチすると、その後 ontouch が機能しないことです。ontouch をズームしなくても問題なく動作します。

4

1 に答える 1

1

削除OnTouchListenerして代わりに使用する

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);
    }
}; 

ディスパッチャーについて詳しく知りたい場合は、ここようこそ

于 2013-09-27T12:39:52.313 に答える