【发布时间】:2019-08-08 12:06:27
【问题描述】:
我的应用有一个非常奇怪的问题。我有带有标签的AppBarLayout 和ViewPager。我已经为ViewPager 配置了所有内容,页面在单击选项卡时切换,但选项卡(选项卡按钮)上的涟漪效应在单击时被中断。当我将TabLayout 移出AppBarLayout 时,问题消失了,当我将layout:paddingTop 添加到AppBarLayout 时,有时会显示波纹,但除此之外,波纹没有正确显示,除非在当前选定的选项卡上。
AppBarLayout:
<com.google.android.material.appbar.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/app_bar_layout"
style="@style/Theme.appBarLayout">
<androidx.appcompat.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
style="@style/Theme.toolbar"
app:layout_scrollFlags="scroll|snap"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:title="@string/app_name_text" />
<com.google.android.material.tabs.TabLayout
android:id="@+id/home_tabs_layout"
style="@style/Theme.tabs"
app:tabIndicatorAnimationDuration="@android:integer/config_shortAnimTime"
app:tabIndicatorColor="@color/primary_dark"
app:tabIndicatorHeight="?attr/actionBarSize"
app:tabMode="fixed"
app:tabUnboundedRipple="false" />
父布局:
<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"
style="@style/Theme.home"
tools:context=".activities.HomeActivity">
<include
layout="@layout/actionbar_tabbed"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<androidx.appcompat.widget.FitWindowsLinearLayout
style="@style/Theme.home.container">
<androidx.viewpager.widget.ViewPager
android:id="@+id/home_view_pager"
style="@style/Theme.pager"
android:layout_below="@id/home_tabs_layout" />
</androidx.appcompat.widget.FitWindowsLinearLayout>
我还尝试使用 android studio 为带有ViewPager 的标签提供的预创建活动重现问题,并且行为是相同的。
提前谢谢你。
【问题讨论】:
-
另外,请查看 Google 引入的新工具,例如 Jetpack 架构工具集中引入的导航组件。看到这个:youtube.com/watch?v=Y0Cs2MQxyIs
标签: android android-viewpager ripple