12

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>
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
DennisVA
  • 2,068
  • 1
  • 25
  • 35
  • 2
    Finally i got the answer from this link - http://stackoverflow.com/questions/24658428/swiperefreshlayout-webview-when-scroll-position-is-at-top?rq=1 – Ashish Kumawat Feb 25 '16 at 12:02

2 Answers2

2

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);
    }
}
Ashish Kumawat
  • 685
  • 7
  • 22
0

No Solution worked for me. Here is my approach.

 @Override
 public boolean dispatchTouchEvent(MotionEvent event)
 {
super.dispatchTouchEvent(event);
int x = (int)event.getX();
int y = (int)event.getY();
 if(y>800){
     swipeRefreshLayout.setEnabled(false);
 }else {
     swipeRefreshLayout.setEnabled(true);
 }


return false;
}
Akash Jp
  • 162
  • 1
  • 10
  • 1
    While this code snippet may be the solution, [including an explanation](//meta.stackexchange.com/questions/114762/explaining-entirely-‌​code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. – f.khantsis Apr 02 '20 at 10:40