0

How to pinch to zoom in a WebView inside ScrollView?

I know I should have avoided using WebView inside a ScrollView but I have to. I have the following layout:

<ScrollView android:id="@+id/scroll" android:layout_width="match_parent" android:layout_height="wrap_content"> <RelativeLayout android:id="@+id/relativebelowscroll" android:layout_width="match_parent" android:layout_height="match_parent"> <WebView android:id="@+id/jobcontent" android:layout_width="match_parent" android:layout_height="wrap_content" android:animateLayoutChanges="true"> </WebView> <com.google.android.gms.ads.AdView android:id="@+id/adView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/jobcontent" android:visibility="visible" app:adSize="BANNER" app:adUnitId="ca-app-pub-XXXXXXXXXXXXXXXXXX" /> <!--The following should be shown on ad failed to load --> <LinearLayout android:id="@+id/dimage" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/jobcontent" android:background="#367AB8" android:gravity="center_vertical|center_horizontal" android:visibility="visible"> <ImageView android:id="@+id/dimage2" android:layout_width="wrap_content" android:layout_height="50dp" android:layout_gravity="left|center_horizontal" android:src="@drawable/banner_left" android:visibility="visible" /> <ImageView android:id="@+id/dimage3" android:layout_width="wrap_content" android:layout_height="50dp" android:layout_gravity="right" android:src="@drawable/banner_right" android:visibility="visible" /> </LinearLayout> </RelativeLayout> </ScrollView> 

Its working good but the zoom in gesture having some problems as it is inside a ScrollView. I have looked other same questions but they all suggests to remove ScrollView but I cant in this particular case. I have a adview just below WebView so when user scrolls it scrolls all the way to adview but if I dont use ScrollView the scroll ends till the WebView gets its end on scroll. It doesn't scroll below WebView to show that adview. So in this case the ScrollView is needed and can't be removed. If I use this layout than I can pinch zoom but can't scroll below WebView content to show adview.

 <WebView android:id="@+id/jobcontent" android:layout_width="match_parent" android:layout_height="wrap_content" android:animateLayoutChanges="true"> </WebView> <com.google.android.gms.ads.AdView android:id="@+id/adView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/jobcontent" android:visibility="visible" app:adSize="BANNER" app:adUnitId="ca-app-pub-XXXXXXXXXXXXXXX" /> <LinearLayout android:id="@+id/dimage" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/jobcontent" android:background="#367AB8" android:gravity="center_vertical|center_horizontal" android:visibility="visible"> <ImageView android:id="@+id/dimage2" android:layout_width="wrap_content" android:layout_height="50dp" android:layout_gravity="left|center_horizontal" android:src="@drawable/banner_left" android:visibility="visible" /> <ImageView android:id="@+id/dimage3" android:layout_width="wrap_content" android:layout_height="50dp" android:layout_gravity="right" android:src="@drawable/banner_right" android:visibility="visible" /> </LinearLayout> 

Is there any possibility to show pinch to zoom in my situation or get the second layout scroll working till adview?

4
  • Check this stackoverflow.com/questions/33117198/… Commented Oct 26, 2018 at 11:48
  • Thanks @Fustigador . I had a quick look here developer.android.com/reference/android/view/MotionEvent So allowing intercepting touch events only to MotionEvent.ACTION_SCROLL and blocking all others will be the solution for pinch to zoom than? Commented Oct 26, 2018 at 11:58
  • You have also to disallow the ScrollView to intercept the motion event when the webview is intercepting it, but yes, its basically that. Commented Oct 26, 2018 at 12:02
  • @M.Monoo did you manage to solve this? Commented May 12, 2022 at 18:28

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.