2017-07-19 34 views
0

我目前正在与Web服务的应用程序,以及它需要不断更新这个原因,所以我尝试运用拉刷新设计错误SwipeRefreshLayout V4 - 拉刷新

我的浮动按钮消失当我使用SwipeRefreshLayout V4

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> 

这是当我没有实现它

<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.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" 
     ... /> 

</RelativeLayout> 

enter image description here

enter image description here

回答

1

SwipeRefreshLayout应该只包含一个孩子(ListViewRecyclerView等)才能正常工作。

您应该将FloatingActionButtonSwipeRefreshLayout移至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> 
+0

非常感谢你 –