为什么在底部栏后面使用浮动操作按钮

时间:2018-08-26 12:01:24

标签: android floating-action-button

我想要浮动动作按钮位于BottomBar和正面的中间,而不是背面的中间,请指导我解决此问题。我的层代码如下...

<RelativeLayout 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/container"
android:layout_width="match_parent"
android:layout_height="match_parent">

<FrameLayout
    android:id="@+id/content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"/>


<android.support.design.widget.FloatingActionButton
    android:id="@+id/floatingActionButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="31dp"
    android:clickable="true"
    android:elevation="0dp"
    app:backgroundTint="@color/colorPrimaryDark"
    app:borderWidth="0dp"
    app:elevation="8dp"
    app:fabSize="normal"
    app:layout_behavior="helpers."
    app:srcCompat="@drawable/ic_add_black_24dp"
    tools:ignore="VectorDrawableCompat" />

<com.roughike.bottombar.BottomBar
    android:id="@+id/bottomBar"
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:layout_alignParentBottom="true"
    app:bb_tabXmlResource="@xml/bottombar_tabs" />

enter image description here

2 个答案:

答案 0 :(得分:1)

  

相对布局在视图上方排列视图,因此视图按您在xml中声明的顺序排列

因此,请更改视图顺序。

<RelativeLayout 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/container"
android:layout_width="match_parent"
android:layout_height="match_parent">

<FrameLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

<com.roughike.bottombar.BottomBar
android:id="@+id/bottomBar"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
app:bb_tabXmlResource="@xml/bottombar_tabs" />

<android.support.design.widget.FloatingActionButton
android:id="@+id/floatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="31dp"
android:clickable="true"
android:elevation="0dp"
app:backgroundTint="@color/colorPrimaryDark"
app:borderWidth="0dp"
app:elevation="8dp"
app:fabSize="normal"
app:layout_behavior="helpers."
app:srcCompat="@drawable/ic_add_black_24dp"
tools:ignore="VectorDrawableCompat" />

希望它会有所帮助..!

已编辑

 <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:layout_alignParentBottom="true">
    <com.roughike.bottombar.BottomBar
        android:id="@+id/bottomBar_"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        app:bb_tabXmlResource="@xml/bottom_tabs" />
</LinearLayout>

答案 1 :(得分:0)

尝试将FAB的位置更改为底部栏下方。

<RelativeLayout 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/container"
android:layout_width="match_parent"
android:layout_height="match_parent">

<FrameLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

 <com.roughike.bottombar.BottomBar
android:id="@+id/bottomBar"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
app:bb_tabXmlResource="@xml/bottombar_tabs" />



<android.support.design.widget.FloatingActionButton
android:id="@+id/floatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="31dp"
android:clickable="true"
android:elevation="0dp"
app:backgroundTint="@color/colorPrimaryDark"
app:borderWidth="0dp"
app:elevation="8dp"
app:fabSize="normal"
app:layout_behavior="helpers."
app:srcCompat="@drawable/ic_add_black_24dp"
tools:ignore="VectorDrawableCompat" />

</RelativeLayout>

希望这会有所帮助。

还要确保晶圆厂的default elevation少于底部钢筋(8)(6),因此您也需要注意这一点。

相关问题