I have a WebView where I show a WebView . Activity containing a Fragment has a CoordinatorLayout as its parent. I want to collapse the Toolbar when the user scrolls the WebView .
Action layout
<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>
The recommended solution is to use WebView inside NestedScrollView. The XML format for the fragment is as follows.
<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>
This works great when the response to load in WebView is plain HTML. But if the response contains an iframe, then the WebView only fills the view port. I can not scroll the WebView .
Here is an example response in which the WebView does not scroll. Here the height reaches 100%. If I get a fixed height such as 1000dp or something else, I can scroll through the WebView. But I will not get a fixed height from the 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"
Although there is more content in WebView, I cannot scroll it outside the text on March 29

source share