4

I have made an app in which there is a transparent image on the webview. My webview has zoom functionality enabled, but after I put transparent image in a transparent LinearLayout on the Webview, I cannot get zoom enabled. Perhaps the transparent LinearLayout (containing partial transparent image) on the Webview restricts the touch event to be detected on Webview. So how do I solve this ? My application screenshot looks like the image given below.

enter image description here

webview.xml file:-

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <WebView
    android:id="@+id/WebView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:layout_weight="1"
    android:gravity="bottom|center" />
    </RelativeLayout>

search_image.xml file:-

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@null"
    android:orientation="vertical"
    android:id="@+id/overlayLayout"
    android:weightSum="1">
    <ImageView
    android:id="@+id/imageView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@drawable/menu_search"/>
    </LinearLayout>

1 Answers1

0

According to How to enable zoom controls and pinch zoom in a WebView?

Check if you don't have a ScrollView wrapping your Webview.

In my case that was the problem. It seems ScrollView gets in the way of the pinch gesture.

To fix it, just take your WebView outside the ScrollView.

then in your onCreate method use:

    webView.getSettings().setBuiltInZoomControls(true);

And it should working fine here.

Community
  • 1
  • 1
piotrek1543
  • 19,130
  • 7
  • 81
  • 94