3

Я пытаюсь поставить все эти элементы вместе, но я не могу видеть FloatingActionButton Мой код заключается в следующем:Использование CoordinatorLayout с SwipeRefreshLayout и RecyclerView и FloatingActionButton вместе

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
tools:context="xx.xx.xxxx.xxxxxxxx.Activity.MainFragment"> 

<android.support.design.widget.CoordinatorLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <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/my_recycler_view" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_margin="5dp" 
      android:scrollbars="vertical" /> 

     <android.support.design.widget.FloatingActionButton 
      android:id="@+id/fab" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom|end" 
      android:layout_margin="16dp" 
      android:src="@drawable/ic_add_white_24dp" 
      app:fab_colorNormal="@color/btn_accent" 
      app:fab_colorPressed="@color/btn_accent_pressed" 
      app:fab_colorRipple="@color/btn_ripple1" 
      app:fab_shadow="true" /> 

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

Я попытался для переключения SwipeRefreshLayout и положения CoordinatorLayout, а затем появился FloatingActionButton, но я не мог прокручивать вверх, потому что он активировал обновление SwipeRefreshLayout. Как я могу заставить его работать?

ответ

7

Перемещение ФАБ за пределами SwipeRefreshLayout.

<android.support.design.widget.CoordinatorLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <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/my_recycler_view" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_margin="5dp" 
      android:scrollbars="vertical" /> 
    </android.support.v4.widget.SwipeRefreshLayout> 
    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|end" 
     android:layout_margin="16dp" 
     android:src="@drawable/ic_add_white_24dp" 
     app:fab_colorNormal="@color/btn_accent" 
     app:fab_colorPressed="@color/btn_accent_pressed" 
     app:fab_colorRipple="@color/btn_ripple1" 
     app:fab_shadow="true" /> 
</android.support.design.widget.CoordinatorLayout> 
Смежные вопросы