Android Activity 转换 - Window.excludeTarget() 阻止 subview 的转换

标签 android android-transitions appbar android-appbarlayout

我正在尝试使用新的 Transition Api 并希望在两个 Activity 之间实现良好的过渡。这两个 Activity 都包含一个 AppBar 和一个标签式 ViewPager

当我第一次运行转换时,AppBar 在两个 Activity 转换之间淡出并再次出现,所以它看起来像是在闪烁:

enter image description here enter image description here

为了解决这个问题,我尝试通过调用 transition.excludeTarget() 从 Activity 转换中排除 AppBar:

// in onCreate() of the calling activity
Transition transition = new Fade();
transition.excludeTarget(mAppBarLayout, true);
getWindow().setExitTransition(transition);
getWindow().setReenterTransition(transition);

// in onCreate() of the called activity
Transition transition = new Fade();
transition.excludeTarget(mAppBarLayout, true);
getWindow().setEnterTransition(transition);
getWindow().setReturnTransition(transition);

此代码解决了闪烁问题,但引入了一个新问题:ViewPager Tabs 不再有交叉淡入淡出动画:

enter image description here

这是两种布局在 generell 中的样子:

<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        android:background="@color/toolbar_background"
        >
        <android.support.v7.widget.Toolbar
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:titleTextColor="@color/toolbar_icons"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/Base.ThemeOverlay.AppCompat.Dark"
            />
        <com.ogaclejapan.smarttablayout.SmartTabLayoutLight
            android:layout_width="match_parent"
            android:layout_height="48dp"
            />
    </android.support.design.widget.AppBarLayout>
    <android.support.v4.view.ViewPager
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
     />
</android.support.design.widget.CoordinatorLayout>

有没有办法从过渡动画中排除 View /布局但包含其子项?我尝试通过调用 transition.addTarget(mTabs); 添加 ViewPager Tabs,但没有任何效果。

最佳答案

您应该只排除您的工具栏而不是整个 AppBarLayout。

transition.excludeTarget(toolbar, true);

关于Android Activity 转换 - Window.excludeTarget() 阻止 subview 的转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35205664/

相关文章:

android - 将 2 个 fragment (一个 fragment 和一个 ListFragment)作为一个滚动

java - 如果 TTS 不支持卡纳达语,如何用卡纳达语播放文本

java - 在 android studio 中创建单元测试

android - CollapsingToolbarLayout 标题作为共享元素过渡

Flutter 如何创建堆叠式标签栏?

android - 如何在 Flutter 中获取 AppBar 高度

Android:在 NestedScrollView 中滚动以将 View 与可见屏幕顶部对齐

android - 了解 Activity 返回转换

android - 如何将曲线运动应用于过渡?

flutter - 如何在 Flutter 中更改状态栏和应用栏颜色?