The fab button is not visible in layout. Without using listView the fab button is visible but when i add listView, the fab button is not visible.
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.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/my_drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
tools:ignore="HardcodedText">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:id="@ id/contactList"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@ id/fab"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="end|bottom"
android:layout_marginTop="450dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="100dp"
android:src="@drawable/ic_baseline_add" />
</LinearLayout>
<com.google.android.material.navigation.NavigationView
android:id="@ id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/navigation_menu" />
</androidx.drawerlayout.widget.DrawerLayout>
How can i show the fab button in the layout
CodePudding user response:
Try to use the CoordinatorLayout
:
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.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/my_drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
tools:ignore="HardcodedText">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@ id/contactList"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@ id/fab"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="end|bottom"
android:layout_marginTop="450dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="100dp"
android:src="@drawable/ic_baseline_add" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<com.google.android.material.navigation.NavigationView
android:id="@ id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/navigation_menu" />
</androidx.drawerlayout.widget.DrawerLayout>