Я могу реализовать TabLayout
с ViewPager
, но когда прокручивается содержимое внутри ViewPager
(анимация замедления), я не могу провести пальцем влево и вправо, чтобы перейти к другим фрагментам внутри ViewPager
. Мне нужно подождать, пока анимация прокрутки не остановится, а затем провести пальцем.
Ниже приведены некоторые мои фрагменты кода.
У меня есть простой activity_main.xml
макет, как показано ниже.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbarHome"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"/>
<LinearLayout
android:id="@+id/mainContainerLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical">
</LinearLayout>
<android.support.design.widget.BottomNavigationView
android:id="@+id/btmNavView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
app:menu="@menu/menu_main" />
</LinearLayout>
Затем я надуваю фрагмент, содержащий TabLayout
и ViewPager
, в LinearLayout
в середине activity_main.xml
. Этот макет можно увидеть ниже:
<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"
android:orientation="vertical">
<com.pchatanan.sontana.custom_views.AppTabLayout
android:id="@+id/contactTabLayout"
app:tabMode="fixed"
android:layout_height="wrap_content"
android:layout_width="match_parent"
style="@style/AppTabLayout"/>
<android.support.v4.view.ViewPager
android:id="@+id/contactViewPager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Логика внутри моего фрагмента ниже:
fragmentArray = new Fragment[]{new SimpleFragment(), new SimpleFragment(), new SimpleFragment()};
titleArray = new String[]{"fragment1", "fragment2", "fragment3"};
contactPagerAdapter = new AppPagerAdapter(getChildFragmentManager(), fragmentArray, titleArray);
contactViewPager.setAdapter(contactPagerAdapter);
contactViewPager.setOffscreenPageLimit(fragmentArray.length - 1);
contactTabLayout.setupWithViewPager(contactViewPager);