Den*_*sVA 11 android android-webview swiperefreshlayout android-framelayout
我在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>
Run Code Online (Sandbox Code Playgroud)
只需使用 ViewTreeObserver.OnScrollChangedListener 实现您的 Fragment 或 Activity,然后设置监听器,如 webview.getViewTreeObserver().addOnScrollChangedListener(this);
在 onScrollChanged() 方法中这样做
@Override
public void onScrollChanged() {
if (webview.getScrollY() == 0) {
swipeLayout.setEnabled(true);
} else {
swipeLayout.setEnabled(false);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2431 次 |
| 最近记录: |