SwipeRefreshLayout 选项卡布局.Webview 无法向上滚动 [英] SwipeRefreshLayout Tab layout. Webview can't scroll up

查看:36
本文介绍了SwipeRefreshLayout 选项卡布局.Webview 无法向上滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我有一个 Tab 视图,其中有一个 web 视图、一个列表视图和一些其他页面.我希望能够执行 SwipeRefreshLayout 来刷新每个项目.我在每一页上都有这个工作.但是,当我在 webview 中向下滚动时,我无法向上滚动.它触发刷新并重建它.我希望能够在我的网络视图中向上滚动.

Okay so I have a Tab view going inside of which I have a webview, a listview and a few other pages. I want to be able to do a SwipeRefreshLayout to refresh each item. I have this working on each page. But, when I scroll down in a webview I can't scroll back up. It triggers the refresh and rebuilds it. I'd like to be able to scroll up in my webview.

布局的东西

<android.support.v4.widget.SwipeRefreshLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/swipe_container"
    android:layout_width="match_parent"
    android:layout_height="20px"
    android:layout_weight="1"
    android:nestedScrollingEnabled="true">


<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=".Splash$PlaceholderFragment">

    <TextView
        android:id="@+id/section_label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <WebView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/webView"
        android:layout_alignParentTop="true"
        android:layout_alignParentStart="true"
        android:overScrollMode="ifContentScrolls"
        android:nestedScrollingEnabled="false"/>

    <ProgressBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/progressBar"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />

    <ListView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/listView"
        android:layout_centerVertical="false"
        android:layout_centerHorizontal="true"
        android:visibility="visible" />

</RelativeLayout>
</android.support.v4.widget.SwipeRefreshLayout>

SwipeRefreshLayout 正在片段内用于我的选项卡式布局.

The SwipeRefreshLayout is being used inside the fragment for my tabbed layout.

        swipeLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipe_container);

        swipeLayout.setColorScheme(android.R.color.holo_blue_bright,
                android.R.color.holo_green_light,
                android.R.color.holo_orange_light,
                android.R.color.holo_red_light);
        swipeLayout.setOnRefreshListener( new SwipeRefreshLayout.OnRefreshListener() {

                @Override public void onRefresh() {
                    if(getArguments().getInt(ARG_SECTION_NUMBER) == 4 ) {
                        stringArrayList.clear();
                        new updatetheQueue().execute(ctx);
                    }
                    else {
                        swipeLayout.setRefreshing(false);
                    }
                }});

推荐答案

您可以使用 OnScrollChangedListener 来禁用 SwipeRefreshLayoutWebView没有滚动到顶部.

You can use an OnScrollChangedListener to disable SwipeRefreshLayout when the WebView is not scrolled to the top.

// Only enable swipe to refresh if the `WebView` is scrolled to the top.
webView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
  @Override
  public void onScrollChanged() {
     if (webView.getScrollY() == 0) {
         swipeRefreshLayout.setEnabled(true);
      } else {
         swipeRefreshLayout.setEnabled(false);
      }
  }
});

这篇关于SwipeRefreshLayout 选项卡布局.Webview 无法向上滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆