WebView in NestedScrollView scrollt nicht, wenn in der Webinhaltsantwort ein iframe-Element mit einer auf 100% festgelegten Höhe enthalten ist
Ich habe einFragment
wo ich das @ anzeiWebView
. DasActivity
enthält das Fragment hatCoordinatorLayout
als übergeordnetes Element. Ich möchte das @ kollabierToolbar
wenn der Benutzer das @ scrolWebView
.
Aktivitätslayout
<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>
Die empfohlene Lösung besteht darin, WebView in NestedScrollView zu verwenden. Das XML-Layout für das Fragment lautet wie folgt.
<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>
Dies funktioniert einwandfrei, wenn die in WebView zu ladende Antwort einfaches HTML ist. Wenn die Antwort jedoch ein iframe-Element enthält, füllt die WebView nur den Ansichtsport. Ich kann das @ nicht scrollWebView
.
Hier ist die Beispielantwort, in der WebView keinen Bildlauf durchführt. Hier kommt die Höhe als 100%. Wenn ich eine feste Höhe wie 1000dp oder so habe, kann ich im WebView scrollen. Aber ich bekomme keine feste Höhe vom Server.
"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"
Obwohl das WebView mehr Inhalte enthält, kann ich nicht über den Text hinaus scrollen. 29. März