1

В настоящее время я пытаюсь сделать плавающую кнопку действия, но по какой-то причине она продолжает отображать кнопку под моим recylerView. Я попытался возиться с раскладкой, отметкой, и я даже попытался использовать метод .bringToFront() в java-коде.Плавающая кнопка действия не отображается наверху

enter image description here

Activity_main

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

    <RelativeLayout android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <include android:id="@+id/toolbar_actionbar" 
      layout="@layout/toolbar_default" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

     <include 
      android:id="@+id/fab_layout" 
      layout="@layout/fab_layout" 
      android:layout_width="@dimen/fab_button_diameter" 
      android:layout_height="@dimen/fab_button_diameter" 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentEnd="true" /> 

     <FrameLayout android:id="@+id/container" 
      android:layout_width="match_parent" 
      android:clickable="true" android:layout_height="match_parent" 
      android:layout_below="@+id/toolbar_actionbar"> 

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

    </FrameLayout> 

</RelativeLayout> 

<!-- android:layout_marginTop="?android:attr/actionBarSize"--> 
<com.android.expresso.expresso.ScrimInsetsFrameLayout android:id="@+id/scrimInsetsFrameLayout" 
    android:layout_width="@dimen/navigation_drawer_width" 
    android:layout_height="wrap_content" 
    android:fitsSystemWindows="true" 
    android:layout_gravity="start" 
    app:insetForeground="#4000" 
    android:elevation="10dp"> 
    <fragment android:id="@+id/fragment_drawer" 
     android:name="com.android.expresso.expresso.NavigationDrawerFragment" 
     android:layout_width="@dimen/navigation_drawer_width" 
     android:layout_height="match_parent" android:fitsSystemWindows="true" 
     app:layout="@layout/fragment_navigation_drawer" /> 
</com.android.expresso.expresso.ScrimInsetsFrameLayout> 

Fab_layout

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="match_parent"> 

    <ImageButton 
     android:id="@+id/fab_image_button" 
     android:layout_width="@dimen/fab_button_diameter" 
     android:layout_height="@dimen/fab_button_diameter" 
     android:background="@drawable/fab_shape" 
     android:src="@drawable/btn_order_hub"/> 

</FrameLayout> 
+0

Перейдите на официальный FloatingActionButton. И вы можете изменить ScrimInsetsFrameLayout с помощью официального NavigationView. –

+0

http://android-developers.blogspot.in/2015/05/android-design-support-library.html – Harry

+0

спасибо, возможно, глупый надзор, но я не могу использовать Floating Action Button через xml .. мне нужно импортировать что-то особенное? –

ответ

7

fab_layout - последний вид в xml. рисунок в порядке xml - вы рисуете FAB, а после этого другие виды (контейнер), они покрывают FAB

<RelativeLayout android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <include android:id="@+id/toolbar_actionbar" 
     layout="@layout/toolbar_default" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 

    <FrameLayout android:id="@+id/container" 
     android:layout_width="match_parent" 
     android:clickable="true" android:layout_height="match_parent" 
     android:layout_below="@+id/toolbar_actionbar"> 

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

     <include 
      android:id="@+id/fab_layout" 
      layout="@layout/fab_layout" 
      android:layout_width="@dimen/fab_button_diameter" 
      android:layout_height="@dimen/fab_button_diameter" 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentEnd="true" /> 

    </FrameLayout> 
</RelativeLayout> 
+2

FAB также должен иметь высоту, которая сделает ее «сверху» на соответствующих устройствах. – Knossos

+0

правда, но Мэтью Штайнхардт нигде не использует 'elevation', поэтому все будет нарисовано с помощью' elevation' = 0dp. если он использует только «возвышение» без переупорядочения в <5.0 'elevation', не будет соблюдаться, и визуальный эффект будет как настоящий. но его хорошая идея использовать высоту ТАКЖЕ. Обратите внимание, что есть FAB от Google в новой библиотеке Design, проверьте [эту ссылку] (http://android-developers.blogspot.com/2015/05/android-design-support-library.html) – snachmsm