Home > Software design >  floating action button blocks bottom navigation bar
floating action button blocks bottom navigation bar

Time:01-30

I want my floating action button to be over the listview and above the navigation bar but i cant seem to make it work. (the include layour is the navigation bar).

This is how it looks right now

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
    tools:context=".SessionsList">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ListView

            android:id="@ id/lvSessions"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

        <com.google.android.material.floatingactionbutton.FloatingActionButton
            android:id="@ id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|end"
            android:src="@drawable/ic_baseline_add_24"
            android:contentDescription=""
            android:layout_margin="16dp" />

        <include layout="@layout/activity_base"/>

    </FrameLayout>


</LinearLayout>

This is the navigation bar layout code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    tools:context=".BaseActivity">

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@ id/bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        app:itemBackground="@color/orange"
        app:itemIconTint="@drawable/selector"
        app:itemTextColor="@drawable/selector"
        android:layout_gravity="bottom"
        app:menu="@menu/menu_navigation" />

</LinearLayout>

I tried putting it in a frame layout and moving things around but I cant get it to work like I want it to.

CodePudding user response:

Change your main layout like this

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

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


        <ListView
            android:id="@ id/lvSessions"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />


        <include
            android:id="@ id/baseLayout"
            layout="@layout/activity_base"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true" />
        <com.google.android.material.floatingactionbutton.FloatingActionButton
            android:id="@ id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="16dp"
            android:layout_above="@ id/baseLayout"
            android:layout_alignParentEnd="true"
            android:src="@drawable/g1" />

    </RelativeLayout>


</FrameLayout>

And also change activity_base layout like this

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@ id/bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="60dp"
       android:layout_gravity="bottom"
        app:itemBackground="@color/black" />

</LinearLayout>
  • Related