当Web内容响应中包含iframe元素且高度设置为100%时,NestedScrollView内的WebView不会滚动

时间:2016-10-17 09:16:50

标签: android iframe webview

我有Fragment我在其中显示WebView。包含片段的Activity作为其父级CoordinatorLayout。我想在用户滚动Toolbar时折叠WebView

活动布局

    <android.support.design.widget.CoordinatorLayout android:id="@+id/cordinator_layout"
                                                 xmlns:android="http://schemas.android.com/apk/res/android"
                                                 xmlns:app="http://schemas.android.com/apk/res-auto"
                                                 android:layout_width="match_parent"
                                                 android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar_layout"
        android:layout_width="match_parent"
        android:layout_height="@dimen/topic_tile_height"
        app:layout_behavior="android.support.design.widget.NewshuntAppBarLayoutBehavior">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="@dimen/topic_tile_collapsing_toolbar"
            app:layout_scrollFlags="scroll|enterAlways">

            <include layout="@layout/actionbar_news"/>

        </android.support.design.widget.CollapsingToolbarLayout>

        <android.support.design.widget.TabLayout
            android:id="@+id/category_tabs"
            android:layout_width="match_parent"
            android:layout_height="@dimen/topic_slidingtablayout_height"
            android:layout_gravity="bottom"
            android:contentDescription="@string/newspaper_category_tabs"
            android:paddingTop="@dimen/topics_sliding_tab_margin_top"/>
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/news_list_pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        android:contentDescription="@string/categories_pager"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

</android.support.design.widget.CoordinatorLayout>

推荐的解决方案是在NestedScrollView中使用WebView。 片段的XML布局如下。

<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/category_webitem_container"
    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.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">
        <WebView
            android:id="@+id/web_item_content"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
        </WebView>
    </android.support.v4.widget.NestedScrollView>

</android.support.v4.widget.SwipeRefreshLayout>

当要在WebView中加载的响应是简单的HTML时,这可以正常工作。但是,如果响应包含iframe元素,则WebView仅填充视图端口。我无法滚动WebView

以下是WebView无法滚动的示例响应。这里的高度为100%。如果我获得1000dp等固定高度,我可以滚动WebView。但是我从服务器上获得了固定的高度。

"content":"<html>\r\n<head>\r\n\t<title></title>\r\n</head>\r\n<body>\r\n<div><iframe height=\"100%\" src=\"https://sportscafe.in/s3/sc-s3-static-mum.sportscafe.in/kwc/en_fixtures.html\" width=\"100%\"></iframe></div>\r\n</body>\r\n</html>\r\n"

虽然WebView中有更多内容,但我无法将其滚动到3月29日以后的文本

enter image description here

0 个答案:

没有答案