1

I'm looking for a method to disable touch on a webview but keep the zooming and scrolling functions of it. For three weeks I searched a lot and test several methods like: Android disable WebView touch but keep zooming/scrolling Unfortunately the problem is unsolved yet. This is my XML code:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/Main22Activity"
tools:context="com.example.hashemisara.myapplication0.MainActivity">
<WebView
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:id="@+id/webView"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:layout_alignParentTop="true"
    android:focusable="true" />
<ProgressBar
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/progressBar"
    android:height="76dip"
    android:width="76dip"
    android:endColor="#000000"
    android:startColor="@android:color/black"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true"
    android:visibility="visible"
    />
</RelativeLayout>

This is my code in create method:

scroll=false;
ourBrow.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(final View v, final MotionEvent event) {

        single_touch=false;

        if (event.getAction() == MotionEvent.ACTION_MOVE) {
            scroll=true;
        }
        else if (event.getAction() == MotionEvent.ACTION_UP) {
            if(scroll==true)
               single_touch=false;
            else {
                single_touch=true;
                scroll=false;
                 }///else

        }///if

        return single_touch;
    }
});

It seems that a single tap is started with an acton_down and is ended with an action_up. Although the scroll event is composed of one action_down, several action_moves and one action_up. If the move action is detected, the above method returns false and if only an action_down and an action_up is detected, it returns true which means that a single tap is detected. Based on my investigation, if the touchlistener returns true it means that the operation is disabled. However using the above code, the zoom and scroll is done but the single tap event is still not disabled! Please kindly help me to solve this problem.

sara
  • 31
  • 5

0 Answers0