【问题标题】:SwipeRefreshLayout Got Action_Move freezes viewSwipeRefreshLayout Got Action_Move 冻结视图
【发布时间】:2014-11-17 13:20:58
【问题描述】:

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

  • 新闻
  • 其他东西 1
  • 其他东西 2
  • 设置

问题:

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

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

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

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

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

其实就是在冻结的fragment后面有一个Responding Fragment。

我在 ADBLog 中也有这个错误:

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

有什么想法吗??

如果您要求,我可以发布代码。

【问题讨论】:

    标签: android android-fragments navigation-drawer drawerlayout swiperefreshlayout


    【解决方案1】:

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

    首先我的 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>
    

    希望以后能帮到别人。

    【讨论】:

    • 我有一个Activity 和一个NavigationDrawer,它加载了一个Fragment,其中只包含:ListView 在一个SwipeRefreshLayout 中,我也有这个错误......跨度>
    • 不,但我正在寻找不同之处,因为它对你有用,所以我想我的错误就在附近。
    • 你能发布你的xml吗?你的 Fragment 像我一样冰冻吗?
    • 我让它工作了。我不需要发布我的布局,我的问题实际上与这个不同。还是谢谢。
    • 这对我有用。确保您的 RecyclerViews 高度也设置为 wrap_content 并且不是布局中的根视图
    【解决方案2】:

    This answer 为我工作。这是关于清除 onPause() 中的刷新布局。

    【讨论】:

      【解决方案3】:

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

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

      添加RelativeLayout 来包装SwipeRefreshLayout 可以修复您的问题,而不仅仅是在SwipeRefreshLayout 中包含ListView/RecyclerView。我没有尝试过,但我猜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>
      

      【讨论】:

      • 没有为我解决这个问题,我将我的设置从以下更改:Fragment -> SwipeRefresh -> Recycler 到这个 Fragment -> FrameLayout -> SwipeRefresh -> Recycler 但我仍然得到那个错误。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-11
      • 1970-01-01
      • 1970-01-01
      • 2013-02-22
      相关资源
      最近更新 更多