在androidx下,TabLayout ViewPager滑动不流畅。
问题:
滑动ViewPager时,对应的tabItem切到另外一个,而不是在中间停住。
解决方案:
将TabLayout放到ViewPager里面。
<androidx.viewpager.widget.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintTop_toBottomOf="@+id/tab_layout" >
<com.google.android.material.tabs.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/include_title_bar" />
</androidx.viewpager.widget.ViewPager>