Garvi Shah
Garvi Shah

Reputation: 11

WebView inside NestedScrollView in ViewPager2 Shrinks and Does Not Display Content Properly with Multiple Twitter Iframes

I’m working on a layout where I need to display two WebViews inside a NestedScrollView, and this NestedScrollView is placed inside a child fragment of a ViewPager2. The goal is to display HTML content in two parts with an ad shown in between them. However, when I swipe to the page containing the WebView, the WebView shrinks, and it doesn't display the content correctly, especially when there are multiple Twitter iframes in the content.

Layout Structure: Here’s a simplified version of my layout:

<androidx.viewpager2.widget.ViewPager2>
    <Fragment>
        <androidx.core.widget.NestedScrollView>
            <WebView />
            <LinearLayout  />
            <WebView />
        </androidx.core.widget.NestedScrollView>
    </Fragment>
</androidx.viewpager2.widget.ViewPager2>

The content in the WebView is divided into two parts, with an ad inserted in between. I’ve tried setting the height of the WebView to match_parent, but the issue persists. The WebView appears to shrink and does not show the full content correctly after some seconds of loading.

What I Have Tried: Setting android:layout_height="match_parent" on the WebView. Wrapping the WebView in a NestedScrollView. Setting WebView size programmatically in the onPageFinished method.

Expected Behavior: I want the WebView to display the content correctly without shrinking, and for the HTML content to be displayed with the ad in between without any layout issues.

Most important, This issue arises when there are multiple Twitter iframes in the content.

Thanks in advance!

Upvotes: 1

Views: 50

Answers (0)

Related Questions