在webview中向上滚动会导致SwipeRefreshLayout

时间:2015-07-14 16:54:29

标签: android android-webview android-framelayout swiperefreshlayout

我在FrameLayout中有一个WebView,因为我正在创建一个浏览器来添加标签。 FrameLayout位于SwipeRefreshLayout内。

问题:每当我在WebView中快速滚动内容时,工具栏后面会出现刷新图标。它应该只在WebView内容位于顶部时才会发生。它与FrameLayout有关,当我删除它时,问题就消失了。

布局如下:

<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>

2 个答案:

答案 0 :(得分:2)

使用ViewTreeObserver.OnScrollChangedListener实现Fragment或Activity,然后设置Listener,如webview.getViewTreeObserver()。addOnScrollChangedListener(this);

在onScrollChanged()方法中这样做

   Public Function SelectTheFile() As String

    On Error GoTo SelectTheFile_ErrorHandler

            Dim fDialog As Office.FileDialog
            Dim varFile As Variant

            Set fDialog = Application.FileDialog(msoFileDialogFilePicker)

            With fDialog

                .AllowMultiSelect = False
                .Title = "Please select one file"

                If .Show = True Then
                    'For Each varFile In .SelectedItems
                       'SelectTheFile = varFile
                       'Debug.Print SelectTheFile
                    'Next
                    SelectTheFile = .SelectedItems(1)
                    Debug.Print SelectTheFile
                Else
                    Debug.Print "Cancel"
                End If
            End With

            Exit Function '<==== exit here, otherwise code goes on to following section 

    SelectTheFile_ErrorHandler:
        Set fDialog = Nothing
        MsgBox "Error " & Err & ": " & Error(Err)

    End Function

答案 1 :(得分:0)

没有解决方案对我有用。这是我的方法。

 @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;
}