【发布时间】:2018-05-01 06:03:51
【问题描述】:
我可以很好地实现TabLayout 和ViewPager,但是当滚动ViewPager 中的内容(减速动画)时,我无法左右滑动以更改为ViewPager 中的其他片段。我必须等到滚动动画停止后再滑动。
下面是我的一些代码sn-ps。
我有一个简单的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 的片段膨胀到activity_main.xml 中间的LinearLayout。此布局如下所示:
<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);
【问题讨论】:
-
片段的内容是什么,是滚动视图还是回收器视图。
-
@Khemraj 这是一个简单的滚动视图。
标签: android android-fragments android-viewpager android-tablayout