Reputation: 3436
I am creating one app in which i have a requirement of put webview inside scrollview..I am using NestedScrollview. Also, i want to scroll content inside webview.
My webview load one HTML which have map + list of some data. So when i scroll list from web it doesn't work and a scroll of outer Scrollview gets scrolled. I want a map and list both scrollable inside webview.
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:fontFamily="@font/avenirnextltpro_regular"
android:text="df"
android:textColor="@color/black"
android:textSize="@dimen/title_textsizeBig"
/>
......... other views like image, Button etc........
<WebView
android:id="@+id/webviewWalkscore"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
/>
</android.support.v4.widget.NestedScrollView>
In Java file i have added this settings for webview
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setGeolocationEnabled(true);
webview.setVerticalScrollBarEnabled(true);
webview.getSettings().setLoadWithOverviewMode(true);
webview.getSettings().setUseWideViewPort(true);
webview.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
webview.setScrollContainer(true);
webview.loadUrl("<url with map and list>")
Upvotes: 1
Views: 1252
Reputation: 61
try to use custom ViewGroup layout that implements NestedScrollingParent2 and put inside the webview and other views in it. and let the webview implement NestedScrollingChild. In your webview override onTouch or intercepttouch. In your parent layout override dispatchTouch event. pass the touch event to webview then it will be use in ACTION MOVE to call dispatchStartNestedScroll. visit this links. try to get ideas from this. https://github.com/HzwSunshine/NestedWebViewRecyclerViewGroup/blob/master/NestedWebViewRecyclerViewGroup/src/main/java/com/hzw/nested/NestedScrollWebView.java
https://www.programmersought.com/article/62784442040/
Upvotes: 0