I am using TabLayout with ViewPager which are inside the CoordinatorLayout. Here I also have a BottomAppBar With A FAB. Below is the picture of the layout.
Here is my xml code for this layout.
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.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"
tools:context=".activities.MainActivity">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="100dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.material.tabs.TabLayout
android:id="@+id/mainTabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
app:tabGravity="fill"
app:tabInlineLabel="true"
app:tabMode="fixed" />
<androidx.viewpager.widget.ViewPager
android:id="@+id/mainViewPager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/mainBottomAppBar"
style="@style/Widget.MaterialComponents.BottomAppBar.Colored"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:hideOnScroll="true"
app:menu="@menu/main_menu"
app:navigationIcon="@drawable/icon_menu" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/mainFAB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:backgroundTint="@color/colorPrimary"
app:layout_anchor="@id/mainBottomAppBar"
app:srcCompat="@drawable/icon_add"
app:tint="@color/white" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
But the problem is, swipe between tabs (or fragments) is not working. If I write the xml code like below then swipe works without any issue.
<?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=".activities.MainActivity">
<com.google.android.material.tabs.TabLayout
android:id="@+id/mainTabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
app:tabGravity="fill"
app:tabInlineLabel="true"
app:tabMode="fixed" />
<androidx.viewpager.widget.ViewPager
android:id="@+id/mainViewPager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
I am not understanding what changes I need to make. Any kind of solutions or advice would be appreciated. Thanks in advance.
Add the android:fillViewport
attribute in your NestedScrollView
<androidx.core.widget.NestedScrollView
android:fillViewport="true"
..>