1

Tried too many times but failed , Here is the code that I have tried

<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:fillViewport="true">


<WebView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/mainweb">
</WebView>

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

On launching the application nested scroll view is working fine but sometimes webview doesn't scroll.

I inserted webview inside nested scroll view to hide toolbar in fragment activities

Any help will be highly appreciate as I am stuck on this problem from past 7 months

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Manik
  • 153
  • 4
  • 15
  • Possible duplicate of [WebView inside NestedScrollView cannot be scrolled](https://stackoverflow.com/questions/35127845/webview-inside-nestedscrollview-cannot-be-scrolled) – madlymad Sep 30 '18 at 14:52
  • Additionally at https://stackoverflow.com/q/40082553/944070 there is a helpfull comment for a possible solution – madlymad Sep 30 '18 at 14:55
  • Can you try setting the height for the webview to wrap_content. See what response does that give you. Additionally, out of interest, are you referring to vertical scrolling or horizontal scrolling? – Nero Sep 30 '18 at 14:56
  • @Nero vertically and setting height to wrap_content is not working – Manik Sep 30 '18 at 15:04

2 Answers2

0

WebView has there own scroll, So there is not need of NestedScrollView.

Because of NestedScrollView Webview getting scroll issues.

Please try below code for reference:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    tools:context=".MainActivity" >

    <WebView
        android:id="@+id/webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="0dp" />
</RelativeLayout>

You can add parent of webview as your need.like LinearLayout, ConstraintLayout, etc.

Android Geek
  • 8,956
  • 2
  • 21
  • 35
0

You need to add this dependency in build.gradle file

implementation 'com.github.ksoichiro:android-observablescrollview:1.6.0'

In your java class

ObservableWebView webView;

webView.setScrollViewCallbacks(new ObservableScrollViewCallbacks() {
        @Override
        public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {

        }

        @Override
        public void onDownMotionEvent() {

        }

        @Override
        public void onUpOrCancelMotionEvent(ScrollState scrollState) {


            if (scrollState == ScrollState.UP) {

                ((AppCompatActivity)getActivity()).getSupportActionBar().hide();
                // hide your action bar
            } else if (scrollState == ScrollState.DOWN) {
                ((AppCompatActivity)getActivity()).getSupportActionBar().show();
                // show your action bar
            }


        }
    });
Manik
  • 153
  • 4
  • 15