AHBottomNavigation总是在FloatingActionButton的前面

时间:2017-06-05 23:26:05

标签: android android-layout

我尝试在底部导航菜单的顶部创建一个带有FAB的布局,但菜单始终位于按钮上方。 :(

我的layout.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/container"
    tools:context="com.example.mytest.money.MainActivity">

    <android.support.v7.widget.CardView
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/card_view"
        android:layout_width="match_parent"
        android:layout_margin="10dp"
        android:layout_height="110dp"
        android:padding="15dp"
        card_view:cardElevation="2dp"
        card_view:cardCornerRadius="4dp">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="Test" />

    </android.support.v7.widget.CardView>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/bottom_navigation"
        android:layout_alignParentTop="true"
        android:foreground="@color/colorBackground">
    </ScrollView>

    <com.aurelhubert.ahbottomnavigation.AHBottomNavigation
        android:id="@+id/bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:selectedBackgroundVisible="false"
        android:layout_gravity="bottom" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/create_gain_expense"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|center"
        android:layout_margin="15dp"
        android:layout_above="@id/bottom_navigation"
        android:src="@drawable/ic_add_white_24dp"
        app:fabSize="normal" />

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

我的期望:

Expectation

我得到了什么:

Reality

我该怎么做才能改变这个? :d

2 个答案:

答案 0 :(得分:3)

我想问题是,AHBottomNavigation的{​​{1}}比elevationFloatingActionButton,这就是它显示在FloatingActionButton之上的原因。

FloatingActionButton提升默认6dpelevation的默认AHBottomNavigation8dp(来自AHBottomNavigation source)< / p>

尝试将更高elevation设置为FloatingActionButton

<android.support.design.widget.FloatingActionButton
    android:id="@+id/create_gain_expense"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|center"
    android:layout_margin="15dp"
    android:layout_above="@id/bottom_navigation"
    android:src="@drawable/ic_add_white_24dp"
    app:fabSize="normal"
    app:elevation="12dp"
    app:borderWidth="0dp" />

#。您也可以使用android.support.design.widget.BottomNavigationView代替AHBottomNavigation

以下是应用结构的正交视图:

enter image description here

请参阅documentation

希望这会有所帮助〜

答案 1 :(得分:0)

ss

试用此代码:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/container">

    <android.support.v7.widget.CardView
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/card_view"
        android:layout_width="match_parent"
        android:layout_margin="10dp"
        android:layout_height="110dp"
        android:padding="15dp"
        card_view:cardElevation="2dp"
        card_view:cardCornerRadius="4dp">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="Test" />

    </android.support.v7.widget.CardView>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/bottom_navigation"
        android:layout_alignParentTop="true"
        android:foreground="@color/white">
    </ScrollView>

    <android.support.design.widget.BottomNavigationView
        android:layout_width="match_parent"
        android:layout_height="56dp"
        android:layout_weight="1"
        android:layout_gravity="bottom"
        android:background="@color/green"
        app:itemIconTint="@color/white"
        app:itemTextColor="@color/white"
        android:id="@+id/bottomnav"
        app:menu="@menu/main">


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

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/create_gain_expense"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|center"
        android:layout_margin="15dp"
        android:layout_above="@id/bottom_navigation"
        android:src="@drawable/ic_add_black_24dp"
        app:fabSize="normal"
        app:elevation="12dp"
        app:borderWidth="0dp" />

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

您可以将此底部导航栏替换为您自己的。