Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scrolling up in webview causes refresh by SwipeRefreshLayout

I have a WebView inside a FrameLayout, to add tabs because i am creating a browser. The FrameLayout is inside a SwipeRefreshLayout.

The problem: Whenever i scroll the content up fast in the WebView, the refresh icon appears from behind the toolbar. It should only happen when the WebView content is at the top. It has something to do with the FrameLayout, when i remove it, the issue is gone.

The layout looks like this:

<SwipeRefreshLayout
            android:id="@+id/swipeRefresh"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

        <FrameLayout
        android:id="@+id/webViewFrame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"    
        >
        <WebView
            android:id="@+id/webView"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
        </FrameLayout>

</SwipeRefreshLayout>
like image 391
DennisVA Avatar asked Jul 14 '15 16:07

DennisVA


1 Answers

Just implement your Fragment or Activity with ViewTreeObserver.OnScrollChangedListener then set Listener like webview.getViewTreeObserver().addOnScrollChangedListener(this);

In onScrollChanged() method do like this

@Override
public void onScrollChanged() {
    if (webview.getScrollY() == 0) {
        swipeLayout.setEnabled(true);
    } else {
        swipeLayout.setEnabled(false);
    }
}
like image 125
Ashish Kumawat Avatar answered Oct 15 '22 13:10

Ashish Kumawat