4

我有一个带有不同片段的普通 NavigationDrawer:

  • 消息
  • 其他东西 1
  • 其他东西 2
  • 环境

问题 :

NewsFragment 包含一个 SwipeRefreshLayout。我第一次刷新时效果很好。

我可以将片段更改为其他东西 1 和 2 和设置。所以我回到NewsFragment。

现在,当我刷新时,片段冻结了。

DrawerLayout 工作正常(打开/关闭,甚至 ActionBar 标题更改),但主要片段停留在 NewsFragment 并且我无法滚动。但是 scollListner 有效(我有日志),但视图没有改变。

没有 refreshView(swipeRefreshLayout 的顶部),没有滚动,没有响应按钮(焦点,onclick),但只有视觉上。

实际上,它就像一个响应片段在冻结片段的后面。

我在 ADBLog 中也有这个错误:

SwipeRefreshLayout﹕ Got ACTION_MOVE event but don't have an active pointer id.

任何想法 ??

如果你问,我可以发布代码。

4

3 回答 3

11

好的,我找到了解决方案。我发布它是因为它可能发生在每个人身上,这有点无聊(我需要两天时间才能找到)。

首先,我在我的 XML 中有这个,其中包含 SwipeRefreshLayout(一个片段):

<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/news_container_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp"
android:background="@color/news_background">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/news_list_recycle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:dividerHeight="5dp" />


    <ProgressBar
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/news_progress"
        android:visibility="invisible"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />


</RelativeLayout>

所以,要修复这个错误,你只需要在你的 SWIPEREFRESHLAYOUT 中有 RECYCLEVIEW (或列表视图):

所以,我移动我的progressBar 并将RelativeLayout 作为rootView。

结果 :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ProgressBar
    style="?android:attr/progressBarStyleLarge"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/news_progress"
    android:visibility="invisible"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true" />

<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/news_container_refresh"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="5dp"
    android:background="@color/news_background">


    <android.support.v7.widget.RecyclerView
        android:id="@+id/news_list_recycle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:dividerHeight="5dp" />

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

我希望它以后会帮助别人。

于 2014-11-18T10:21:50.013 回答
0

这个答案对我有用。这是关于清除 onPause() 中的刷新布局。

于 2015-03-25T12:27:12.617 回答
-1

您的代码示例确实解决了这个问题。这似乎是 v21 支持库的问题。

为了进一步澄清以帮助可能遇到此问题的其他人,问题似乎SwipeRefreshLayout是不再高兴成为根视图。

添加 aRelativeLayout来包装SwipeRefreshLayout修复您案例中的错误,而不仅仅是ListView/RecyclerViewSwipeRefreshLayout. 我没有尝试过,但我猜一个LinearLayout或其他也可以解决问题。

所以解决方法是:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent">
        <android.support.v4.widget.SwipeRefreshLayout
             android:layout_width="match_parent"
             android:layout_height="match_parent">
                    <!-- List, Layout etc -->
        </android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
于 2014-11-26T12:37:49.103 回答