2

Я пытаюсь рекламировать fab для моего фрагмента, но он скрыт за панелью навигации. Проблема заключается в том, что макет представления интересует его действия, а поведение прокрутки устанавливается в макете фрейма, к которому я прикрепляю фрагмент. Как добавить это поведение в представление recycler во фрагменте без необходимости добавления панели инструментов к фрагменту. Это потому, что у меня есть много фрагментов и только один вид деятельностиПлавающая кнопка действия, скрытая за навигационным ящиком

Navigation_drawer_layout

<?xml version="1.0" encoding="utf-8"?> 

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:openDrawer="close"> 

    <android.support.design.widget.CoordinatorLayout 
     android:id="@+id/coordinatorLayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <android.support.design.widget.AppBarLayout 
      android:id="@+id/appBarLayout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:fitsSystemWindows="true"> 

      <include 
       android:id="@+id/toolbar" 
       layout="@layout/toolbar" /> 
     </android.support.design.widget.AppBarLayout> 


     <FrameLayout 
      android:id="@+id/content_frame" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 

      app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 
    </android.support.design.widget.CoordinatorLayout> 

    <android.support.design.widget.NavigationView 
     android:id="@+id/nav_view" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:theme="@style/NavigationDrawerStyle" 
     app:itemIconTint="@color/PrimaryPurple" 
     app:menu="@menu/activity_dasboard_drawer" /> 


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

fragment_layout

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/coordinatorLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

     <android.support.v7.widget.RecyclerView 
      android:id="@+id/food_queue_recycle_list" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@color/title_white" /> 

     <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto" 
      android:id="@+id/card_view_no_items" 
      android:layout_width="350dp" 
      android:layout_height="200dp" 
      android:layout_centerInParent="true" 
      android:visibility="gone" 
      card_view:cardCornerRadius="2dp" 
      card_view:cardElevation="4dp"> 

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

       <ImageView 
        android:id="@+id/errorImageView" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_alignParentTop="true" 
        android:layout_centerHorizontal="true" 
        android:contentDescription="@string/empty_favourite_list" 
        android:src="@drawable/food_icon_empty" /> 

       <TextView 
        android:id="@+id/errorTextView" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_below="@+id/errorImageView" 
        android:layout_marginTop="@dimen/large_text_size" 
        android:gravity="center" 
        android:text="@string/empty_favourite_list" 
        android:textAllCaps="true" 
        android:textColor="@color/SecondaryBlack" 
        android:textSize="@dimen/medium_text_size" 
        android:textStyle="bold" /> 
      </RelativeLayout> 
     </android.support.v7.widget.CardView> 
    </RelativeLayout> 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/action_edit" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|end" 
     android:layout_margin="@dimen/fab_margin" 
     android:src="@drawable/ic_mode_edit_48px" 
     app:backgroundTint="@color/PrimaryPurple" 
     app:layout_anchor="@id/food_queue_recycle_list" 
     app:layout_anchorGravity="bottom|right|end" 
     app:layout_behavior="helpers.FABCoordinatorBehavior" /> 
</android.support.design.widget.CoordinatorLayout> 

enter image description here

+3

Этот тип проблемы распространен прямо сейчас, когда вы устанавливаете FloatingActionButton в фрагменте. FAB действительно предназначены для перехода в Activity, чтобы они могли анимировать и выходить. Переместите координаторLayout и FAB в макет действия, и просто получите RecyclerView в фрагменте. В Управлении вызовите show() и скройте() в FAB, чтобы показать его при необходимости. –

+0

Хорошо, спасибо за подтверждение. –

+0

Аналогичная проблема здесь, но немного отличается от вашей настройки: http://stackoverflow.com/questions/35194672/floatingactionbutton-in-fragment-hidden-on-toolbar-collapsing –

ответ

2

right.you Daniel NUGENT может сделать это так:

Просто поместите FloatingActionButton на этом mainlayout, как это:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:openDrawer="close"> 

    <android.support.design.widget.CoordinatorLayout 
     android:id="@+id/coordinatorLayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <FrameLayout 
      android:id="@+id/content_frame" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

     <android.support.design.widget.AppBarLayout 
      android:id="@+id/appBarLayout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:fitsSystemWindows="true"> 

      <include 
       android:id="@+id/toolbar" 
       layout="@layout/toolbar" /> 

     </android.support.design.widget.AppBarLayout> 

     <android.support.design.widget.FloatingActionButton 
      android:id="@+id/action_edit" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom|end" 
      android:layout_margin="@dimen/fab_margin" 
      android:src="@drawable/ic_mode_edit_48px" 
      app:backgroundTint="@color/PrimaryPurple" 
      app:layout_anchor="@id/food_queue_recycle_list" 
      app:layout_anchorGravity="bottom|right|end" 
      app:layout_behavior="helpers.FABCoordinatorBehavior" /> 

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

    <android.support.design.widget.NavigationView 
     android:id="@+id/nav_view" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:theme="@style/NavigationDrawerStyle" 
     app:itemIconTint="@color/PrimaryPurple" 
     app:menu="@menu/activity_dasboard_drawer" /> 

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

И затем использовать это RecyclerView внутри, что Fragment:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/coordinatorLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/food_queue_recycle_list" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/title_white" /> 

    <!-- not sure about this, but, it shouldn't be here --> 

    <!--<android.support.v7.widget.CardView 
     android:id="@+id/card_view_no_items" 
     android:layout_width="350dp" 
     android:layout_height="200dp" 
     android:layout_centerInParent="true" 
     android:visibility="gone" 
     card_view:cardCornerRadius="2dp" 
     card_view:cardElevation="4dp"> 

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

      <ImageView 
       android:id="@+id/errorImageView" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentTop="true" 
       android:layout_centerHorizontal="true" 
       android:contentDescription="@string/empty_favourite_list" 
       android:src="@drawable/food_icon_empty" /> 

      <TextView 
       android:id="@+id/errorTextView" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/errorImageView" 
       android:layout_marginTop="@dimen/large_text_size" 
       android:gravity="center" 
       android:text="@string/empty_favourite_list" 
       android:textAllCaps="true" 
       android:textColor="@color/SecondaryBlack" 
       android:textSize="@dimen/medium_text_size" 
       android:textStyle="bold" /> 
     </RelativeLayout> 
    </android.support.v7.widget.CardView>--> 

</RelativeLayout> 

я не был уверен, что CardView, потому что вы установили RecyclerView в match_parent на:

<android.support.v7.widget.RecyclerView 
     android:id="@+id/food_queue_recycle_list" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/title_white" /> 

Итак, этих карт не должно быть. (unless you need to show it as error cards), установив setVisibility до GONE и после этого обрабатывать, если была ошибка, показать ее: setVisibility == View.VISIBLE.

+0

. Эти карты являются карточкой ошибки, когда нет предметов. Они отличаются от предметов ресайлера. –

+0

Добавлено в ответ. – Mohsen

Смежные вопросы