Android 设计错误SwipeRefreshLayout v4-拉入刷新

Android 设计错误SwipeRefreshLayout v4-拉入刷新,android,Android,我目前正在制作一个带有web服务的应用程序,出于这个原因,它需要经常更新,所以我尝试应用Pull来刷新 当我使用SwipeRefreshLayout v4时,我的浮动按钮消失 <android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:fab="http://schemas.android.com/apk/res-auto

我目前正在制作一个带有web服务的应用程序,出于这个原因,它需要经常更新,所以我尝试应用Pull来刷新

当我使用SwipeRefreshLayout v4时,我的浮动按钮消失

<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:fab="http://schemas.android.com/apk/res-auto"
    android:id="@+id/fragment_main"
    ...>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/reciclador"
        ..../>

    <com.melnykov.fab.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ... />   

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

<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:fab="http://schemas.android.com/apk/res-auto"
    android:id="@+id/fragment_main"
    ...>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/reciclador"
        ..../>

    <com.melnykov.fab.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ... />   

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

之后


SwipeRefreshLayout
应仅包含一个子项(
ListView
RecyclerView
等)才能正常工作

您应该将
FloatingActionButton
SwiperFreshLayout
移动到您的
RelativeLayout
。这应该会有所帮助

最终布局标记应如下所示:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:fab="http://schemas.android.com/apk/res-auto"
    android:id="@+id/fragment_main"
    ....>

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipe_refresh_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        ... >

        <android.support.v7.widget.RecyclerView
            android:id="@+id/reciclador"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            ... />

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

    <com.melnykov.fab.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ... />   

</RelativeLayout>